|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: extracting all elem names of an attribute
At 2004-01-23 02:04 -0500, Saverio Perugini wrote:
How best is the following text extracted from the following xml, possibly using keys or some other xslt constructs? ... The basic approach involves: Gee, that sounds like a good approach to me: - using keys to get a unique list of possible values for the @category attribute <xsl:key name="cats" match="*[@category]" use="@category"/> - iterating over these values
- printing each followed by a colon <xsl:value-of select="@category"/>: <xsl:text/> - getting a unique list of all xml element names which contain this particular attribute value
printing each <xsl:value-of select="name(.)"/> printing an endline
Many thanks For what? You already understand the solution! :{)} ...................... Ken p.s. you have a typo in your XML data, unless you like peepers on your pizza t:\ftemp>type saverio.xml
<db>
<large category="size">
<thin category="crust">
<olives category="topping"/>
<pepperoni category="topping"/>
</thin>
<pan category="crust">
<pepperoni category="topping"/>
</pan>
</large>
<medium category="size">
<pan category="crust">
<pepperoni category="topping"/>
<olives category="topping"/>
<peppers category="topping"/>
</pan>
</medium>
<small category="size">
<thin category="crust">
<olives category="topping"/>
<pepperoni category="topping"/>
<peepers category="topping"/>
</thin>
<pan category="crust">
<pepperoni category="topping"/>
<olives category="topping"/>
<peepers category="topping"/>
</pan>
</small>
</db>t:\ftemp>type saverio.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"><xsl:output method="text"/> <xsl:key name="cats" match="*[@category]" use="@category"/> <xsl:template match="/">
<xsl:for-each select="//*[@category]
[generate-id(.)=generate-id(key('cats',@category)[1])]">
<xsl:value-of select="@category"/>: <xsl:text/>
<xsl:for-each select="key('cats',@category)">
<xsl:if test="generate-id(.)=
generate-id(key('cats',@category)[name(.)=name(current())][1])">
<xsl:if test="generate-id(.)!=
generate-id(key('cats',@category)[1])">, </xsl:if>
<xsl:value-of select="name(.)"/>
</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template></xsl:stylesheet> t:\ftemp>saxon saverio.xml saverio.xsl size: large, medium, small crust: thin, pan topping: olives, pepperoni, peppers, peepers t:\ftemp>
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc 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
|

Cart








