[Home] [By Thread] [By Date] [Recent Entries]
At 2008-08-04 12:38 -0500, James Sulak wrote:
I have a sequence of nodes stored in a variable, Perhaps you only have a tree and not a sequence of nodes. and I am attempting to filter it using an XPath expression that includes the "except" operator. However, it's not working like I expect it to. Nope! Just a declaration issue I think. You don't show your declaration of $normalized_data, so I'm going to assume you just made it a temporary tree and you didn't make it a variable of "data" elements. My students of XSLT 2 who know XSLT 1 have had a problem with this when jumping on the temporary tree bandwagon, thinking they are getting variables of nodes, until I tell them about the use of the as= to direct the processor in the expected use of the variable. I hope the example below helps illustrate the difference ... please let me know if this is not the source of your problem. You can see the only difference is how I declared the nodes stored in the variable. . . . . . . . . . . . Ken
<xsl:output indent="yes"/> <xsl:variable name="normalized_data"> <data id="1"> <info action="delete" /> <info action="insert" /> <stuff /> </data> <data id="2"> <info action="insert" /> <stuff /> </data> <data id="3"> <stuff /> </data> </xsl:variable> <xsl:variable name="normalized_data_ken" as="element(data)+"> <data id="1"> <info action="delete" /> <info action="insert" /> <stuff /> </data> <data id="2"> <info action="insert" /> <stuff /> </data> <data id="3"> <stuff /> </data> </xsl:variable> <xsl:template match="/"> <results> <james> <olddata> <xsl:sequence select="$normalized_data[not(info/@action='delete')] except $normalized_data[info/@action='insert' or info/@action='modify']" /> </olddata> </james> <ken> <xsl:sequence select="$normalized_data_ken[not(info/@action='delete')] except $normalized_data_ken[info/@action='insert' or info/@action='modify']" /> </ken> </results> </xsl:template> </xsl:stylesheet> T:\ftemp>call xslt2 james.xsl james.xsl james.xml T:\ftemp>type james.xml
<?xml version="1.0" encoding="UTF-8"?>
<results>
<james>
<olddata>
<data id="1">
<info action="delete"/>
<info action="insert"/>
<stuff/>
</data>
<data id="2">
<info action="insert"/>
<stuff/>
</data>
<data id="3">
<stuff/>
</data>
</olddata>
</james>
<ken>
<data id="3">
<stuff/>
</data>
</ken>
</results>
T:\ftemp>rem Done!
|

Cart



