[xslt] "|" operator
- From: Phil Shafer <phil juniper net>
- To: The Gnome XSLT library mailing-list <xslt gnome org>
- Subject: [xslt] "|" operator
- Date: Wed, 12 Dec 2007 16:05:58 -0500
This may be a dumb question, but I'm stumped.....
What's the difference between 'select=". | one"'
and 'select="(.) | one"'? The latter does what
I thought the former should have done.
Here's is a script that does five selects and calls a
template that for-each'es thru the selected nodes and
prints their name():
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="top">
<out>
<test1>
<xsl:variable name="test1" select=". | one"/>
<xsl:call-template name="out">
<xsl:with-param name="test" select="$test1"/>
</xsl:call-template>
</test1>
<test2>
<xsl:variable name="test2" select="(.) | one"/>
<xsl:call-template name="out">
<xsl:with-param name="test" select="$test2"/>
</xsl:call-template>
</test2>
<test3>
<xsl:variable name="top" select="."/>
<xsl:variable name="test2" select="$top | one"/>
<xsl:call-template name="out">
<xsl:with-param name="test" select="$test2"/>
</xsl:call-template>
</test3>
<test4>
<xsl:variable name="test1" select=". or one"/>
<xsl:call-template name="out">
<xsl:with-param name="test" select="$test1"/>
</xsl:call-template>
</test4>
<test5>
<xsl:variable name="test1" select="(.) or one"/>
<xsl:call-template name="out">
<xsl:with-param name="test" select="$test1"/>
</xsl:call-template>
</test5>
</out>
</xsl:template>
<xsl:template name="out">
<xsl:param name="test"/>
<xsl:for-each select="$test">
<found>
<name><xsl:value-of select="name(.)"/></name>
</found>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Here is my test input:
<top>
<one/>
<two/>
<three/>
</top>
The output of xsltproc (formatted) is:
<?xml version="1.0"?>
<out>
<test1>
<found>
<name>top</name>
</found>
</test1>
<test2>
<found>
<name>top</name>
</found>
<found>
<name>one</name>
</found>
</test2>
<test3>
<found>
<name>top</name>
</found>
<found>
<name>one</name>
</found>
</test3>
<test4/>
<test5/>
</out>
The problem is that ". | one" selects only <top>, not <one>.
But if I wrap it in parens (test2) or use a variable (test3), it
works correctly.
My first guess was this was an issue with "|" as both the logic and
union operators, but test4 and test5 indicate otherwise (since
nothing was selected).
Any insight appreciated.
Thanks,
Phil
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]