Created
March 1, 2011 15:11
-
-
Save Flackus/849258 to your computer and use it in GitHub Desktop.
Challenge 2.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<result> | |
<r> | |
<position>3</position> | |
<content> | |
<div class="b"> | |
<div class="c"> | |
<b>...</b> | |
<!-- мы тут --> | |
</div> | |
</div> | |
</content> | |
</r> | |
<r> | |
<position>1</position> | |
<content></content> | |
</r> | |
<r> | |
<position>4</position> | |
<content> | |
<i class="b"> | |
<div class="GR"> | |
<span></span> | |
</div> | |
<div class="b"> | |
<div class="c"> | |
<c> | |
<!-- мы тут --> | |
<test> | |
<ololo>...</ololo> | |
</test> | |
</c> | |
</div> | |
<div class="GR"> | |
<span></span> | |
</div> | |
</div> | |
</i> | |
</ololo> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<div class="a"> | |
<i> | |
<div class="b"> | |
<div class="c"> | |
<b>...</b> | |
<!-- мы тут --> | |
</div> | |
</div> | |
</i> | |
</div> | |
<div class="a"> | |
<div> | |
<d>...</d> | |
<!-- мы тут --> | |
</div> | |
</div> | |
<div> | |
<ololo> | |
<i class="b"> | |
<div class="GR"> | |
<span></span> | |
</div> | |
<div class="b"> | |
<div class="c"> | |
<c> | |
<!-- мы тут --> | |
<test> | |
<ololo>...</ololo> | |
</test> | |
</c> | |
</div> | |
<div class="GR"> | |
<span></span> | |
</div> | |
</div> | |
</i> | |
</ololo> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> | |
<xsl:template match="/"> | |
<result> | |
<xsl:apply-templates/> | |
</result> | |
</xsl:template> | |
<xsl:template match="b | c | d"> | |
<r> | |
<xsl:variable name="index"> | |
<xsl:apply-templates select="ancestor::*[not(@class)][1]" mode="count"> | |
<xsl:with-param name="pId" select="generate-id()"/> | |
</xsl:apply-templates> | |
</xsl:variable> | |
<position> | |
<xsl:value-of select="$index"/> | |
</position> | |
<content> | |
<xsl:copy-of select="ancestor::*[position() < number($index)][last()]"/> | |
</content> | |
</r> | |
</xsl:template> | |
<xsl:template match="*" mode="count"> | |
<xsl:param name="pId"/> | |
<xsl:value-of select=" | |
count( | |
descendant::* | |
[descendant-or-self::*[generate-id() = $pId]] | |
[not(ancestor::*[generate-id() = $pId])] | |
) | |
"/> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment