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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + How to add page number in to v... (2)
-> + XSL Grouping (7)
-> + Repeat images using FOR EACH l... (7)
-> + How to get File name (2)
-> + image and text on the same lin... (2)
-> + Create XSLT stylesheets for us... (2)
-> + Merge Multiple Files While Che... (2)
-> + xslt 3 level or multi level gr... (6)
-> + How to create xsl which will c... (2)
-> + xsl:variable and Result Tree F... (7)
-> - XSL-FO fo:table continued from... (1)
-> + XSLT Java issue (2)
-> + problem with hyperlink (4)
-> + substring-after function probl... (4)
-> + Xalan Processing (3)
-> + Memory utilization high with m... (2)
-> + check all parent node groups s... (2)
-> + CSV DOC to XML CONVERSION (11)
-> + XSLT: Ordered List (based on r... (4)
-> + XSLT Mapping - Issue (4)
-> + XSL following-sibling, how to ... (5)
-> + need xslt elements help (2)
-> + Dynamic generation of URL in X... (2)
-> + List Created from Section Navi... (2)
-> + xslt elements help (2)
-> + Map field if source is not nul... (3)
-> + XSLT group and sort whith gene... (4)
-> + Nested XML value (2)
-> + Specifying condition with coun... (4)
-> + xsl:function using found in er... (4)
-> + How to remove an unwanted spac... (2)
-> + Question about variable substi... (2)
-> + XSL for Comparing nodes and di... (4)
-> + External lookup list (8)
-> + XSL HTML output now needs to b... (2)
-> + Adding a new sub element to th... (4)
-> + How do I get rid of 'Tip' node... (9)
-> + Trying to dynamically create n... (2)
-> + Display XML link, using XSLT a... (9)
-> + calling templates based on ord... (2)
-> + How to add internal links usin... (4)
-> + How to call user defined java ... (3)
-> + XSLT and WebApps past and futu... (3)
-> + passing condition through java... (3)
-> + Apllying a template from withi... (4)
-> + Getting xsl element in javascr... (3)
-> + The document() function inside... (3)
-> + Footnote text move to para (2)
-> + XSL: multiple element come to ... (3)
-> + How to use following-sibling &... (2)
-> + How to use FOP 0.95 with Stylu... (4)
-> + Error during creating PDF from... (2)
-> + Help creating a comma delimite... (4)
-> + Selective Add using XSLT recur... (3)
-> + Help: convert without parent e... (2)
-> - Correct my substring function ... (1)
-> + Old xsl into reports (4)
-> + How to save xslt converted fil... (3)
-> + How to find non tagging text? (5)
-> + Help: Hex entity to Character... (6)
-> + EDI QUOTES MESSAGE NEED TO REP... (2)
-> + How to convert in multi level ... (4)
-> + Need some help with a styleshe... (3)
-> - Conditional Formattinf Formula... (1)
-> + Creating HTML Unordered LIsts.... (2)
-> + xslt params uknown number of i... (2)
-> + How to use fonts other than ba... (2)
-> - Converting existing HTML into ... (1)
-> + Help to tune up this XSLT (2)
-> + XSLT - is only converting the ... (2)
-> + XSLT Editor tab (4)
-> + Convert multiple files from XM... (2)
-> + how to use in select expressi... (2)
-> + Help needed in XSL transformat... (2)
-> + How to add a string with math ... (5)
-> + How to add a string with math ... (6)
-> - br element (1)
-> + Stylesheet directed terminatio... (2)
-> + Who can help me whit sum funct... (2)
-> + XSLT Works in Stylus Studio, n... (3)
-> - Filter by Attribute (1)
-> + Display x number of items whic... (6)
-> + MultiColumn Reporting (3)
-> + cant get namespace declaration... (3)
-> + Performance xsl:for each and n... (3)
-> + How to assign value to a XSLT ... (3)
-> + Select element value based on ... (2)
-> + Version 10 of Saxon? (8)
-> + How to get the value of a node... (5)
-> + Display Xpath using (4)
-> + XSLT to report (2)
-> + xslt help for a noobie (2)
-> + XSL-FO XML to PDF with XSLT (3)
-> + Using XSLT to transform XML to... (4)
-> + XSLT to sort a list alphabetic... (4)
-> + How to Get Colum Values based ... (2)
-> + non persisting predicate filte... (5)
-> + HTML to XSLT (2)
-> + extra carriage returns in "csv... (2)
-> + extra carriage returns in "csv... (3)
-- Previous [301-320] [321-340] [341-360] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Surekha PalaparthySubject: Looping in XSLT
Author: Surekha Palaparthy
Date: 16 Aug 2005 04:59 AM
Hi
I need to transform an XML file into another XML .I have two questions regarding making XSLT file for this.

Q1)There are elements in the XML file which specify the count through which the loop should be processed.I dont know as to how to go ahead with the looping inside an XSLT.Can anyone please help me out in this.The count is equal to the value of "CountVal" element in the sample XML file given.
The loop should be in such a way that i can get the respective XSL(CountVal)Val element's value .Similar is the case with CountRet.Also notice that since i have the count of CountRet as 3,the output XML file has XSLRet val as "-",though there is a XSLT4Val in the original XMl file .


Q2)As you motice ,there are two other elements VALIndex and RETIndex in the original XMl file which hold an array of values.

I find this to be toooo tricky..Not up with a solution....Please help me as early as possible..Waiting for the input from your side.


This is the original XML file.

<?xml version="1.0"?>
<Main >
<Step1>
<Step4>
<Apply>true</Apply>
<Name>CountVal</Name>
<Value>5</Value>
</Step4>
<Step4>
<Apply>true</Apply>
<Name>CountRet</Name>
<Value>3</Value>
</Step4>
<Step4>
<Apply>true</Apply>
<Name>XSL1Val</Name>
<Value>124</Value>
</Step4>
<Step4>
<Apply>true</Apply>
<Name>XSL2Val</Name>
<Value>13</Value>
<Step4>
<Apply>true</Apply>
<Name>XSL3Val</Name>
<Value>12</Value>
</Step4>
<Step4>
<Apply>true</Apply>
<Name>XSL4Val</Name>
<Value>14</Value>
</Step4>
<Step4>
<Apply>true</Apply>
<Name>XSL5Val</Name>
<Value>124</Value>
</Step4>
<Step4>
<Apply>true</Apply>
<Name>XSL6Val</Name>
<Value>12</Value>
</Step4>
<Step4>
<Apply>true</Apply>
<Name>XSL7Val</Name>
<Value>12</Value>
</Step4>
<Step4>
<Apply>true</Apply>
<Name>Xsl1Ret</Name>
<Value>10</Value>
</Step4>
<Step4>
<Apply>true</Apply>
<Name>XSL2Ret</Name>
<Value>124</Value>
<Step4>
<Apply>true</Apply>
<Name>XSL3Ret</Name>
<Value>12</Value>
</Step4>
<Step4>
<Apply>true</Apply>
<Name>XSL4Ret</Name>
<Value>14</Value>
</Step4>
<Step4>
<Apply>true</Apply>
<Name>VALIndex</Name>
<Value>3;1;2;4;0;0;0;0;0;0;</Value>
</Step4>
<Step4>
<Apply>true</Apply>
<Name>RETIndex</Name>
<Value>2;4;3;1;0;0;0;0;0;0;</Value>
</Step4>
</Step1>
</Main>

The output xml file that I want to retrieve is also given below.

Output XML:
-------------------------------------------------------
<?xml version="1.0"?>
<Main >
<Table1>
<XSLVal>124</XSLVal>
<XSLRet>10</XSLVal>
<VALIndex>3</VALIndex>
<RETIndex>2</RETIndex>
</Table1>
<Table2>
<XSLVal>13</XSLVal>
<XSLRet>124</XSLVal>
<VALIndex>1</VALIndex>
<RETIndex>4</RETIndex>
</Table2>
<Table3>
<XSLVal>12</XSLVal>
<XSLRet>12</XSLVal>
<VALIndex>2</VALIndex>
<RETIndex>3</RETIndex>
</Table3>
<Table3>
<XSLVal>14</XSLVal>
<XSLRet>-</XSLVal>
<VALIndex>4</VALIndex>
<RETIndex>1</RETIndex>
</Table3>
</Main>


Thanks in Advance

Postnext
Ivan PedruzziSubject: Looping in XSLT
Author: Ivan Pedruzzi
Date: 16 Aug 2005 09:53 AM

The attached XSLT should give you a start.

Hope this helps
Ivan Pedruzzi
Stylus Studio team


Documentxsltval.xsl

Posttop
Surekha PalaparthySubject: Looping in XSLT
Author: Surekha Palaparthy
Date: 17 Aug 2005 09:40 AM
Thanks a lot for your help!!
This is indeed a great help for a beginner .
I started implementing the way as suggested by you.

I am attaching the OriginalXml and xsl files.
As you notice ,the xml output file generated is a bit different from what i expect.I want only the first four tables to be pritned,instead it repeats itself.Can you suggest as to why its happening so

Please Copy paste into a notepad .These are working fine at my side
/************************************
Original xml file

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="EXTPPOST2.xsl"?>
<Main >
<Main1>
<Main2>
<Main3>
<Content>
<Name>Count</Name>
<Value>4</Value>
</Content>
<Content>
<Name>Array</Name> <Value>1;2;3;4;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;</Value>
</Content>
<Content>
<Name>Item1Val</Name>
<Value>10</Value>
</Content>
<Content>
<Name>Item2Val</Name>
<Value>20</Value>
</Content>
<Content>
<Name>Item3Val</Name>
<Value>30</Value>
</Content>
<Content>
<Name>Item4Val</Name>
<Value>40</Value>
</Content>
<Content>
<Name>Item5Val</Name>
<Value>50</Value>
</Content>
<Content>
<Name>Item6Val</Name>
<Value>60</Value>
</Content>
<Content>
<Name>Item7Val</Name>
<Value>70</Value>
</Content>
<Content>
<Name>Item8Val</Name>
<Value>80</Value>
</Content>
<Content>
<Name>Item9Val</Name>
<Value>90</Value>
</Content>
</Main3>
</Main2>
</Main1>
</Main>
/****************************************************

Xsl file

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>

<xsl:variable name= "MainCount" select="number(Main/Main1/Main2/Main3/Content[Name='Count']/Value/text())"/>

<xsl:template match="/">
<NewDataSet>
<xsl:apply-templates select="Main/Main1/Main2/Main3/Content">
<xsl:with-param name="NoCount" select="$MainCount"/>
<xsl:with-param name="Array" select="Main/Main1/Main2/Main3/Content[Name='Array']/Value/text()"/>
</xsl:apply-templates>
</NewDataSet>
</xsl:template>

<xsl:template match="Content">
<xsl:param name="NoCount"/>
<xsl:param name="Array"/>

<xsl:if test="$NoCount > 0" >
<Table1>
<Count>
<xsl:value-of select="$MainCount - $NoCount + 1"/>
</Count>
<Array>
<xsl:value-of select="substring-before($Array,';')"/>
</Array>
<Item>
<xsl:value-of select="following-sibling::Content[Name=concat('Item',$MainCount - $NoCount + 1,'Val')]/Value"/>
</Item>
</Table1>

<xsl:apply-templates select="following-sibling::Content[Name=concat('Item',$MainCount - $NoCount + 1,'Val')]">
<xsl:with-param name="NoCount" select="$NoCount - 1"/>
<xsl:with-param name="Array" select="substring-after($Array,';')"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
/*****************************************************************
Output xml that I view
<NewDataSet>
- <Table1>
<Count>1</Count>
<Array>1</Array>
<Item>10</Item>
</Table1>
- <Table1>
<Count>2</Count>
<Array>2</Array>
<Item>20</Item>
</Table1>
- <Table1>
<Count>3</Count>
<Array>3</Array>
<Item>30</Item>
</Table1>
- <Table1>
<Count>4</Count>
<Array>4</Array>
<Item>40</Item>
</Table1> <!--I want the data to be pritned only till here
- <Table1>
<Count>1</Count>
<Array>1</Array>
<Item>10</Item>
</Table1>
- <Table1>
<Count>2</Count>
<Array>2</Array>
<Item>20</Item>
</Table1>
- <Table1>
<Count>3</Count>
<Array>3</Array>
<Item>30</Item>
</Table1>
- <Table1>
<Count>4</Count>
<Array>4</Array>
<Item>40</Item>
</Table1>
- <Table1>
<Count>1</Count>
<Array>1</Array>
<Item />
</Table1>
- <Table1>
<Count>1</Count>
<Array>1</Array>
<Item />
</Table1>
- <Table1>
<Count>1</Count>
<Array>1</Array>
<Item />
</Table1>
- <Table1>
<Count>1</Count>
<Array>1</Array>
<Item />
</Table1>
- <Table1>
<Count>1</Count>
<Array>1</Array>
<Item />
</Table1>
- <Table1>
<Count>1</Count>
<Array>1</Array>
<Item />
</Table1>
- <Table1>
<Count>1</Count>
<Array>1</Array>
<Item />
</Table1>
- <Table1>
<Count>1</Count>
<Array>1</Array>
<Item />
</Table1>
- <Table1>
<Count>1</Count>
<Array>1</Array>
<Item />
</Table1>
</NewDataSet>

Thanks once again

   
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.