[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: How do can I select distinct nodes and adding a co
Dear Ismaël >I know what you mean, but the problem I have is how do I produce a tree with >distinct values that I can access afterwards. This is essentially a grouping problem. You can use xsl:key to group elements according to a particular value. This will allow you to access the distinct values as a nodeset, without having to put them in a variable and use an extension function. [from your first email] > The second one looks like this: > > <xx> > <xxx>.1.5.6.3.8 > <xxxx att1=".1.5.6.3.8"/> > <xxx> > <xxx>.1.5.6.3.10 > <xxxx att2="1.5.6.3.9"/> > <xxx> > <xxx>.1.5.6.4.5</xxx> > </xx> [...] > What I want to do know is getting out of the second xml file the > values of the attributes mapped onto an odd number (5,7,9) when this > attribute is available. When not available the text value of the tag must be > used. The only hard bit is setting up the key so that it ignores the text value of the xxx tag if there's an xxxx child with an attribute. <xsl:key name="distinctlyXXX" match="xxx" use="self::xxx[not(xxxx/@*)]|xxxx/@*"/> <!-- group on the xxxx child's first attribute, if it exists, otherwise on the text value of xxx --> <xsl:variable name="first_path" select="firstFile.xml"/> <xsl:variable name="first" select="document($first_path)"/> <xsl:variable name="first_count_maps" select="count($first/mapping/map)"/> <xsl:template match="xx"> <mapping> <xsl:copy-of select="$first/mapping/map"/> <xsl:apply-templates select="xxx[generate-id() = generate-id(key('distinctlyXXX', self::xxx[not(xxxx/@*)]|xxxx/@*))]"/> <!-- this is classic Muenchian grouping --> </mapping> </xsl:template> <xsl:template match="xxx"> <map oid="{string(self::xxx[not(xxxx/@*)] | xxxx/@*)}" id="{(position() + $first_map_count) * 2 - 1}"> <xsl:value-of select=". | xxxx/@*"/> </map> </xsl:template> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|