|
Subject: Re: [xsl] extracting all elem names of an attribute From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 23 Jan 2004 07:25:12 -0500 |
How best is the following text extracted from the following xml, possibly using keys or some other xslt constructs? ... The basic approach involves:
- using keys to get a unique list of possible values for the @category attribute
- iterating over these values
<xsl:for-each select="//*[@category] [generate-id(.)=generate-id(key('cats',@category)[1])]">
- printing each followed by a colon
- getting a unique list of all xml element names which contain this particular attribute value
- iterating over these values
<xsl:for-each select="key('cats',@category)"> <xsl:if test="generate-id(.)= generate-id(key('cats',@category)[name(.)=name(current())][1])">
printing each
printing an endline
<xsl:text> </xsl:text>
Many thanks
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: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>t:\ftemp>saxon saverio.xml saverio.xsl size: large, medium, small crust: thin, pan topping: olives, pepperoni, peppers, peepers
-- Public courses: sign up for one or both soon to reserve your seat! Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO Washington, DC: 2004-03-15 San Francisco, CA: 2004-03-22 Hong Kong, China: 2004-05-17 Bremen, Germany: 2004-05-24 World-wide on-site corporate, government & user group XML training
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
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] extracting all elem names of , Saverio Perugini | Thread | [xsl] XSLT to SVG for Chess, Strange, Mark (ACHA) |
| [xsl] increment value - unique elem, Ricardo Saraiva | Date | [xsl] dereferencing count() within , Andrew Maclean |
| Month |