XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Julio de la VegaSubject: Problems with for-each and a template
Author: Julio de la Vega
Date: 31 Aug 2007 09:10 AM
Hi *,

Why REG_20/Desc has no information? My template REG_20 is not working properly.
Could you please help me to undertand what is wrong in my xsl?

Thanks in advance.

<?xml version='1.0' encoding='US-ASCII' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="US-ASCII" indent="yes"/>
<xsl:key name="next" match="REG_20" use="generate-id(preceding-sibling::REG_10[1])"/>
<xsl:template match="/">
<root>
<xsl:apply-templates select="root/REG_10"/>

</root>
</xsl:template>
<xsl:template match="REG_10">
<REG_10>
<xsl:copy-of select="*"/>
<xsl:apply-templates select="key('next', generate-id())"/>
</REG_10>
</xsl:template>

<xsl:template match="REG_20">
<REG_20>
<xsl:for-each select="REG_20/Cod">
<xsl:value-of select="REG_20/Desc"/>
</xsl:for-each>
</REG_20>
</xsl:template>
</xsl:stylesheet>


My example xml input data:

root>
<REG_10>
<Datos1>Datos1</Datos1>
<Datos2>Datos2</Datos2>
<Datos3>Datos3</Datos3>
</REG_10>
<REG_20>
<Numoc>3</Numoc>
<Cod>1</Cod>
<Desc>Descripcion1</Desc>
<Valor>1000</Valor>
<Cod>2</Cod>
<Desc>Descripcion2</Desc>
<Valor>2000</Valor>
<Cod>3</Cod>
<Desc>Descripcion3</Desc>
<Valor>3000</Valor>
</REG_20>
<REG_10>
<Datos1>Datos4</Datos1>
<Datos2>Datos5</Datos2>
<Datos3>Datos6</Datos3>
</REG_10>
<REG_20>
<Numoc>4</Numoc>
<Cod>4</Cod>
<Desc>Descripcion4</Desc>
<Valor>4000</Valor>
<Cod>5</Cod>
<Desc>Descripcion5</Desc>
<Valor>5000</Valor>
<Cod>6</Cod>
<Desc>Descripcion6</Desc>
<Valor>6000</Valor>
<Cod>7</Cod>
<Desc>Descripcion7</Desc>
<Valor>7000</Valor>
</REG_20>


Applicationfiles.rar
Files

Posttop
Julio de la VegaSubject: Problems with for-each and a template
Author: Julio de la Vega
Date: 03 Sep 2007 04:31 AM
I hope this help:

My final solution (thank you Toni):

<?xml version='1.0' encoding='US-ASCII' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="US-ASCII" indent="yes"/>

<xsl:key name="next" match="REG_20" use="generate-id(preceding-sibling::REG_10[1])"/>

<xsl:template match="/">
<root>
<xsl:apply-templates select="root/REG_10"/>

</root>
</xsl:template>


<xsl:template match="REG_10">
<REG_10>
<xsl:copy-of select="*"/>
<xsl:apply-templates select="key('next', generate-id())"/>
</REG_10>
</xsl:template>


<xsl:template match="REG_20">
<REG_20>
<xsl:copy-of select="Numoc"/>
<xsl:for-each select="Cod">
<Dato>
<xsl:copy-of select="."/>
<xsl:copy-of select="following-sibling::Desc[1]"/>
<xsl:copy-of select="following-sibling::Valor[1]"/>
</Dato>
</xsl:for-each>
</REG_20>
</xsl:template>


</xsl:stylesheet>

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.