|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Build unique nodeset when Key can't be used?
At 01/10/17 13:45 +0100, J S Publications wrote:
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>. My earlier note today shows how this can be done without keys but with local variables. I've used XT (which doesn't support key()) and I've included an example of how the members could be counted. I hope you find the solution below useful. ................ Ken
<xsl:output method="text"/> <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></xsl:stylesheet> 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 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








