p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

xslt thread: Transforming XML using XSL


Message #1 by "Luis Vizuete" <luis@d...> on Mon, 9 Sep 2002 10:45:13
Your code:

<xsl:template match=3D"pais">
		<xsl:apply-templates select=3D"//sitio"></xsl:apply-
templates>
</xsl:template>

selects all the <sitio> elements in the document. But I think you only
want those that belong to the current <pais>. So change it to:

<xsl:apply-templates select=3D".//sitio">

or more efficiently,

<xsl:apply-templates select=3D"sitios/sitio">

Michael Kay
Software AG
home: Michael.H.Kay@n...
work: Michael.Kay@s...

> -----Original Message-----
> From: Luis Vizuete [mailto:luis@d...]
> Sent: 09 September 2002 10:45
> To: P2P_XSLT
> Subject: [xslt] Transforming XML using XSL
>
>
> Hi,
> I'm working with XML but i have some problems:
>
> I need an HTML page from XML but this HTML have to be created with a
> condition, only i need elements that its code is 1.
> I have the next XML.
>
> <?xml version=3D"1.0" encoding=3D"UTF-8"?>
> <?xml-stylesheet type=3D"text/xsl" href=3D"Prueba.xsl"?>
> <todo>
> 	<paises>
> 		<pais id=3D"1">
> 			<sitios>
> 				<sitio id=3D"ES00001363">
> 					<codigo>001</codigo>
> 					<nombre>Sitio1</nombre>
> 				</sitio>
> 				<sitio id=3D"ES00001364">
> 					<codigo>002</codigo>
> 					<nombre>Sitio2</nombre>
> 				</sitio>
> 			</sitios>
> 		</pais>
> 		<pais id=3D"2">
> 			<sitios>
> 				<sitio id=3D"ES00003">
> 					<codigo>003</codigo>
> 					<nombre>Sitio3</nombre>
> 				</sitio>
> 			</sitios>
> 		</pais>
> 	</paises>
> </todo>
>
> My XSL is the next:
> <?xml version=3D"1.0" encoding=3D"UTF-8"?>
> <xsl:stylesheet version=3D"1.0"
> xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform">
> <xsl:template match=3D"/">
> <html>
> <body>
> <table border=3D"1">
> <thead>
> 	<tr>
> 		<th>ID</th>
> 		<th>Codigo</th>
> 		<th>Nombre</th>
> 	</tr>
> </thead>
> <tbody>
> 	<xsl:apply-templates select=3D"//pais[@id=3D'1']"/>
> </tbody>
> </table>
> </body>
> </html>
> </xsl:template>
>
> <xsl:template match=3D"pais">
> 		<xsl:apply-templates select=3D"//sitio"></xsl:apply-
> templates>
> </xsl:template>
>
> <xsl:template match=3D"sitio">
> 	<tr>
> 		<td><xsl:value-of select=3D"@id"/>	</td>
> 		<td><xsl:value-of select=3D"codigo"/></td>
> 		<td><xsl:value-of select=3D"nombre"/></td>
> 	</tr>
> </xsl:template>
> </xsl:stylesheet>
>
> With this XML and XSL, I have to obtain datas from sitio1 and
> sitio 2, but
> I don=B4t know because also obtain data from sitio3 if I change
> the next
> line:
> <xsl:apply-templates select=3D"//pais[@id=3D'1']"/>
> for this
> <xsl:apply-templates select=3D"//pais[@id=3D'2']"/>
> occurs the same, but if put this line
> <xsl:apply-templates select=3D"//pais[@id=3D'3']"/>
> The results is nothing
>
> Anybody know why???
>
> Thanks.
> ---
> In developing the .NET Framework Microsoft has
> taken XML to heart, and with ASP.NET representing
> the cutting edge of Windows based web development,
> Professional ASP.NET XML with C# has been published
> to help web developers to appreciate how these
> technologies can work together to provide
> functional, powerful applications.
> http://www.wrox.com/acon11.asp?ISBN=3D1861007345
>


  Return to Index