EDN Admin
Well-known member
I have observed a problem with XPath incorect select result of XSL template.
I have a following example data:
<pre><?xml version="1.0" encoding="utf-8"?>
<root>
<branch id="1
<element id="4"/>
<element id="5"/>
</branch>
<branch id="2
<element id="6"/>
</branch>
<branch id="3"/>
</root>
[/code]
Than I have simple XSL temp:
<pre><?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform
<xsl:template match="/root
<output>
<xsl:variable name="id" select=".//*/@id"/>
<xsl:comment>
<xsl:text>$id = </xsl:text>
<xsl:value-of select="$id"/>
</xsl:comment>
<xsl:for-each select=".//*[@id=$id][1]
<xsl:copy-of select="."/>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>[/code]
If I apply them, I obtain a wrong result like this:
<pre><?xml version="1.0" encoding="utf-8"?>
<output>
<!--$id = 1-->
<branch id="1
<element id="4"/>
<element id="5"/>
</branch>
<element id="4"/>
<element id="6"/>
</output>
[/code]
The items <element id="4"/> and <element id="6"/> have no reason to be in the result - thay have different @id value!!
<span style="color:#0000ff; font-size:xx-small
<span style="color:#0000ff; font-size:xx-small Please help!
View the full article
I have a following example data:
<pre><?xml version="1.0" encoding="utf-8"?>
<root>
<branch id="1
<element id="4"/>
<element id="5"/>
</branch>
<branch id="2
<element id="6"/>
</branch>
<branch id="3"/>
</root>
[/code]
Than I have simple XSL temp:
<pre><?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform
<xsl:template match="/root
<output>
<xsl:variable name="id" select=".//*/@id"/>
<xsl:comment>
<xsl:text>$id = </xsl:text>
<xsl:value-of select="$id"/>
</xsl:comment>
<xsl:for-each select=".//*[@id=$id][1]
<xsl:copy-of select="."/>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>[/code]
If I apply them, I obtain a wrong result like this:
<pre><?xml version="1.0" encoding="utf-8"?>
<output>
<!--$id = 1-->
<branch id="1
<element id="4"/>
<element id="5"/>
</branch>
<element id="4"/>
<element id="6"/>
</output>
[/code]
The items <element id="4"/> and <element id="6"/> have no reason to be in the result - thay have different @id value!!
<span style="color:#0000ff; font-size:xx-small
<span style="color:#0000ff; font-size:xx-small Please help!
View the full article