Subject: Re: [xsl] Style questions (2 questions) From: David Carlisle <davidc@xxxxxxxxx> Date: Thu, 25 Aug 2005 15:08:37 +0100 |
> But you cant do that with keys ... can you? related to the parallel thread re xslt1/xslt2, just a note that you can do this fairly easily with keys in xslt2 as you can get more expressivity into the use attribute of xsl:key. <x> <post tag="reference xml" href="..." /> <post tag="reference xml xslt" href="..." /> <post tag="reference xml css" href="..." /> <post tag="reference html" href="..." /> <post tag="reference html 1" href="..." /> <post tag="reference html 2" href="..." /> <post tag="reference html 3rip" href="..." /> <post tag="reference html 3.2" href="..." /> <post tag="reference html 4" href="..." /> <post tag="linux" href="..." /> </x> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" /> <xsl:key name="t" match="post" use="for $i in (1 to count(tokenize(@tag,' +'))) return string-join(tokenize(@tag,' +')[position()<=$i],' ')"/> <xsl:template match="/"> 1 reference xml <xsl:copy-of select="key('t','reference xml')"/> 2: linux <xsl:copy-of select="key('t','linux')"/> 3: reference <xsl:copy-of select="key('t','reference')"/> 4: reference html <xsl:copy-of select="key('t','reference html')"/> 4: reference html 4 <xsl:copy-of select="key('t','reference html 4')"/> </xsl:template> </xsl:stylesheet> $ saxon8 keys.xml keys.xsl <?xml version="1.0" encoding="UTF-8"?> 1 reference xml <post tag="reference xml" href="..."/> <post tag="reference xml xslt" href="..."/> <post tag="reference xml css" href="..."/> 2: linux <post tag="linux" href="..."/> 3: reference <post tag="reference xml" href="..."/> <post tag="reference xml xslt" href="..."/> <post tag="reference xml css" href="..."/> <post tag="reference html" href="..."/> <post tag="reference html 1" href="..."/> <post tag="reference html 2" href="..."/> <post tag="reference html 3rip" href="..."/> <post tag="reference html 3.2" href="..."/> <post tag="reference html 4" href="..."/> 4: reference html <post tag="reference html" href="..."/> <post tag="reference html 1" href="..."/> <post tag="reference html 2" href="..."/> <post tag="reference html 3rip" href="..."/> <post tag="reference html 3.2" href="..."/> <post tag="reference html 4" href="..."/> 4: reference html 4 <post tag="reference html 4" href="..."/> ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Style questions (2 questi, Wendell Piez | Thread | Re: [xsl] Style questions (2 questi, iwantto keepanon |
[xsl] Copy an XML file as it is whi, Khorasani, Houman | Date | Re: [xsl] Copy an XML file as it is, David Carlisle |
Month |