[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: A better solution...

Subject: RE: A better solution...
From: "Casadome, Francisco Javier" <Francisco.Casadome@xxxxxxxxxxxxxx>
Date: Thu, 25 Oct 2001 10:45:37 +0200
RE:  A better solution...
Yes you are right, I wanted (//Section[@Title=$S])[1]
I can't use the apply templates because the second template is recursive
(it calls itself many times). :/

-----Original Message-----
From: Jarno.Elovirta@xxxxxxxxx [mailto:Jarno.Elovirta@xxxxxxxxx] 
Sent: jueves, 25 de octubre de 2001 10:26
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  A better solution...

> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:output method="html" omit-xml-declaration="yes" 
> indent="no"/>
> 
> 	<xsl:param name="S"/>
> 
> 	<xsl:template match="/Sections">
> 		<xsl:for-each select="//Section[@Title=$S][1]">
> 			<xsl:call-template name="SubS"/>
> 		</xsl:for-each>
> 	</xsl:template>
> 
> 	<xsl:template name="SubS" match="Section">
> 		<!- ... -->
> 	</xsl:template>
> 
> </xsl:stylesheet>
> 
> This applies the 2nd template to the first occurrence of node 
> Section with
> attribute Title equal to the parameter S.

I think you want

  (//Section[@Title=$S])[1]

> The XML looks like this (sections can be nested up to any level):
> 
> <Sections>
> 	<Section Title="1">
> 		<Section Title="2"/>
> 		<Section Title="4"/>
> 		<Section Title="8">
> 			<Section Title="9"/>
> 		</Section>
> 	</Section>
> 	<Section Title="3">
> 		<Section Title="2"/>
> 	</Section>
> 	...
> </Sections>
> 
> What I don't like is to have to use a for-each to select the node.
> Any ideas ?

Why not simply do

	<xsl:template match="/Sections">
		<xsl:apply-template select="(//Section[@Title=$S])[1]" />
	</xsl:template>

Jarno

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.