[xslt] "|" operator
- From: Phil Shafer <phil juniper net>
- To: The Gnome XSLT library mailing-list <xslt gnome org>
- Subject: [xslt] "|" operator
- Date: Fri, 11 Jul 2008 15:01:44 -0400
I have another odd xslt question:
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 three 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>
</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>
</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. Any insight appreciated.
Thanks,
Phil
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]