Subject: Re: [xsl] Getting specific elements from a list From: JBryant@xxxxxxxxx Date: Thu, 26 May 2005 16:08:45 -0500 |
Hi, Joe, The thing that's tripping you up is that the EnumValueDescription elements don't share the same context, so [1] and [last()] don't do what you want. The trick is to get them into the same context, which I did with a variable in the following stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable name="EVDs" select="//EnumValueDescription"/> <xsl:template match="tblEnumeratedTypes"> test ( int, <xsl:value-of select="EnumeratedType"/>, <xsl:value-of select="$EVDs[1]"/>, <xsl:value-of select="$EVDs[last()]"/> ); </xsl:template> </xsl:stylesheet> The output (with Saxon 8.4): test ( int, ColorType, Red, Blue ); You could do it with a key, too, and I'm sure there are yet other ways (but variable and key came to mind right off). Jay Bryant Bryant Communication Services (presently consulting at Synergistic Solution Technologies) "Simon, Jb" <jb.simon@xxxxxxxx> 05/26/2005 03:37 PM Please respond to xsl-list@xxxxxxxxxxxxxxxxxxxxxx To xsl-list@xxxxxxxxxxxxxxxxxxxxxx cc Subject [xsl] Getting specific elements from a list Hi, I have the following XML snippit : <tblEnumeratedTypes> <EnumeratedType>ColorType</EnumeratedType> <tblEnumValues> <EnumeratedType>ColorType</EnumeratedType> <EnumValueDescription>Red</EnumValueDescription> </tblEnumValues> <tblEnumValues> <EnumeratedType>ColorType</EnumeratedType> <EnumValueDescription>White</EnumValueDescription> </tblEnumValues> <tblEnumValues> <EnumeratedType>ColorType</EnumeratedType> <EnumValueDescription>Blue</EnumValueDescription> </tblEnumValues> </tblEnumeratedTypes> What I need as output is TEST ( int, ColorType, Red, Blue ) The problem I'm having is getting the Red and Blue, basically, the First and last EnumeratedType element of EnumeratedTypes. I tried various combinations, although it seems this should have worked... <xsl:template match="tblEnumeratedTypes_WC" mode="range-macro"> test ( int, <xsl:value-of select="EnumeratedType"/>, <xsl:value-of select=".//EnumValueDescription[1]"/>, <xsl:value-of select=".//EnumValueDescription[last()]"/> ) ; </xsl:template> When I execute that I get (line breaks are not a problem) TEST ( int, ColorType, Red, Red ) ; What is the problem is that I can never get the last Value to be Blue. Oh, XSL Procesor : Microsoft (R) XSLT Processor Version 4.0 Also tried it using Mozilla, same result Any Ideas ? TIA Joe Simon
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Getting specific elements, Dimitre Novatchev | Thread | RE: [xsl] Getting specific elements, Michael Kay |
[xsl] remove duplicates in each big, Pedro Sá da Costa | Date | RE: [xsl] Getting specific elements, Simon, Jb |
Month |