Subject: Re: [xsl] Build unique nodeset when Key can't be used? From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Wed, 17 Oct 2001 09:21:45 -0400 |
I have a <paragraph> element that can contain one or more <link> elements. Each <link> has a @type and a @id attributes. When @type='Figure' the link is to an image. I want to output each <paragraph>, followed by a list of pictures referenced in the <paragraph>.
...
How can I get a list with just one entry for each image? I can't see how to you key, because key is a root-level element and so can't work with just the current <paragraph>. I have tried for-each but can't come up with a select that returns a 'unique' node-set.
T:\chris>type chris.xml <?xml version="1.0" encoding="utf-8"?> <book> <para> <link type="Figure" id="fig1"/> <link type="Figure" id="fig2"/> <link type="Figure" id="fig1"/> </para> <para> <link type="Figure" id="fig1"/> <link type="Figure" id="fig3"/> <link type="Figure" id="fig5"/> </para> <para> <link type="Figure" id="fig4"/> <link type="Figure" id="fig2"/> <link type="Figure" id="fig2"/> </para> </book> T:\chris>type chris.xsl <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/XSL/Format" version="1.0">
<xsl:template match="/"> <xsl:apply-templates select="//para"/> </xsl:template>
<xsl:template match="para"> <xsl:text/>Paragraph summary: <xsl:text/> <xsl:variable name="figs" select="link[@type='Figure']"/> <xsl:for-each select="$figs"> <xsl:sort select="@id"/> <xsl:variable name="figure-id" select="@id"/> <xsl:if test="generate-id(.)= generate-id($figs[@id=$figure-id])"> <xsl:text>Figure id: </xsl:text> <xsl:value-of select="$figure-id"/> <xsl:text> - </xsl:text> <xsl:value-of select="count($figs[@id=$figure-id])"/> <xsl:text> time</xsl:text> <xsl:if test="count($figs[@id=$figure-id])>1"> <xsl:text>s</xsl:text> </xsl:if> <xsl:text> </xsl:text> </xsl:if> </xsl:for-each> </xsl:template>
T:\chris>xt chris.xml chris.xsl Paragraph summary: Figure id: fig1 - 2 times Figure id: fig2 - 1 time Paragraph summary: Figure id: fig1 - 1 time Figure id: fig3 - 1 time Figure id: fig5 - 1 time Paragraph summary: Figure id: fig2 - 2 times Figure id: fig4 - 1 time
-- 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 (Fax:-0995) Web site: XSL/XML/DSSSL/SGML/OmniMark services, training, products. Book: Practical Transformation Using XSLT and XPath ISBN 1-894049-06-3 Article: What is XSLT? http://www.xml.com/pub/2000/08/holman/index.html Next public training (instructor-live, Internet-live, and web-based): -2001-10-22,11-01,11-02,11-05,11-19,11-21,12-03,12-05,12-09,12-10,12-19
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Build unique nodeset when Key, J S Publications | Thread | Re: [xsl] Build unique nodeset when, David Carlisle |
Re: [xsl] Saxon custom extensions p, Gustaf Liljegren | Date | Re: [xsl] Build unique nodeset when, David Carlisle |
Month |