Sign Up
Search
Options
search
Chat
Help
News
Log in
Not Logged in
Home
»
Boards
»
Stylus Studio Developer Network
»
XSLT Help and Discussion
»
Problems with for-each and a template
Conferences
Stylus Studio Feature Requests
(1192)
Stylus Studio Technical Forum
(14621)
Website Feedback
(249)
XSLT Help and Discussion
(7625)
Use of before and after string
(3)
How do I substitute element ty...
(1)
How does one add working days ...
(4)
Help, I have existing XLT and...
(1)
Need help on XSLT issue -
(2)
EDI to XML Conversion
(7)
XML To JSON Conversion using X...
(1)
Formatting Paragraphs to same ...
(2)
Grouping of records
(1)
Problems with xsd 1.1
(4)
XML to HL7 mapping
(3)
XSLT 3 and Iterate
(2)
XSL-FO to PDF preview
(3)
java.lang.RuntimeException: Er...
(2)
Create Acroforms with Stylus X...
(2)
How to change XSLT parameter s...
(3)
how to change format of the da...
(2)
Search "Next 8 Results " doesn...
(2)
Support for Git
(1)
newbee
(8)
[1-20]
[21-40]
[41-60]
Next
XQuery Help and Discussion
(2017)
Stylus Studio FAQs
(159)
Stylus Studio Code Samples & Utilities
(364)
Stylus Studio Announcements
(113)
Topic
next
Subject:
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>
files.rar
Files
top
Subject:
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>
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 to Conference:
Select Conference
Stylus Studio Feature Requests
Stylus Studio Technical Forum
Website Feedback
XSLT Help and Discussion
XQuery Help and Discussion
Stylus Studio FAQs
Stylus Studio Code Samples & Utilities
Stylus Studio Announcements
go
Log In Options
Username:
Password:
Site Map
|
Privacy Policy
|
Terms of Use
|
Trademarks
Stylus Scoop XML Newsletter:
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.