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)
-> + Add Condition check in a multi... (3)
-> + Eliminating Duplicates with XS... (3)
-> + Empty tags in XML (2)
-> + XML to XML transformations (5)
-> + XSLT problem (3)
-> - XSLT and Array (6)
-> ->XSLT and Array
-> ->XSLT and Array
-> ->XSLT and Array
-> ->XSLT and Array
-> ->XSLT and Array
-> + Problem with transforming XMLs... (3)
-> + Logging in XSLT? (3)
-> + svg can not view with msxml pr... (3)
-> + Newbie Sorting Question (5)
-> + xslt - get values from fist no... (5)
-> + RenderX logo at the buttom of ... (2)
-> + consolidate same nodes into on... (4)
-> + HOW DO I GET THE XSLT MAPPER? (2)
-> + Newbie - dublicating attribute... (2)
-> + Correct use of sum() (3)
-> + Using the sum() function (4)
-> + Prublem in XSLT (6)
-> + Newbie XPath Question (10)
-> + Reference to variable or param... (3)
-- Previous [1381-1400] [1401-1420] [1421-1440] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Dink LoSubject: XSLT and Array
Author: Dink Lo
Date: 10 Aug 2006 03:16 AM
Hi all,

I'm new in the XSLT field. I have a strange problem and it seems to need something like array in the XSLT style.
This is my XML:
<WorkList>
<Item>
<Name>aaa</Name>
<Quantity>10</Quantity>
</Item>
<Item>
<Name>bbb</Name>
<Quantity>5</Quantity>
</Item>
</WorkList>
<SubTotalList>
<Detail>
<UnitPrice>10</UnitPrice>
<Amount>100</Amount>
</Detail>
<Detail>
<UnitPrice>5</UnitPrice>
<Amount>25</Amount>
</Detail>
</SubTotalList>

The XML needs to be presented like this:
Name Quantity UnitPrice Amount
aaa 10 10 100
bbb 5 5 25

I think the pseudo code of the XSLT should be like:
<xsl:for-each select="WorkList/Item">
<TR>
<TD><xsl:value-of select="Name"/></TD>
<TD><xsl:value-of select="Quantity"/></TD>
<TD>SubTotalList.Detail[i].UnitPrice</TD>
<TD>SubTotalList.Detail[i].Amount</TD>
i++;
</TR>
</xsl:for-each>

However I can't find the mapping XSLT presentation to the pseudo code. Can somebody help me to make the XSLT presentation?

Thanks in advance,

Dink

Postnext
Ivan PedruzziSubject: XSLT and Array
Author: Ivan Pedruzzi
Date: 10 Aug 2006 08:58 AM

Hi Lo,

Which Stylus Studio version are you running?



Ivan Pedruzzi
Stylus Studio Team

Postnext
Dink LoSubject: XSLT and Array
Author: Dink Lo
Date: 10 Aug 2006 09:32 PM
Hi Ivan,

I just use the notepad to make up the xslt stylesheet.
Can anyone give me some directions?

Thanks,

Dink

Postnext
James DurningSubject: XSLT and Array
Author: James Durning
Date: 10 Aug 2006 03:12 PM
You're creating one row for each detail, what if you have no subtotal list? eg your first item does not.

<xsl:for-each select="WorkList/Item/SubTotalList/Detail">
<TR>
<TD><xsl:value-of select="../../Name"/></TD>
<TD><xsl:value-of select="../../Quantity"/></TD>
<TD><xsl:value-of select="UnitPrice"/></TD>
<TD><xsl:value-of select="Amount"/></TD>
</TR>
</xsl:for-each>

Postnext
Dink LoSubject: XSLT and Array
Author: Dink Lo
Date: 10 Aug 2006 09:39 PM
Hi James,

Thanks for your suggestion.
However the XML schema is defined and it's better not to change it.
So I need to make up a XSLT stylesheet to complement the bad defined XML Schema. Can you give me some advice?

Thanks,

Dink

Posttop
Dink LoSubject: XSLT and Array
Author: Dink Lo
Date: 15 Aug 2006 05:07 AM
Hello,

I've tried a lot of ways to solve this problem.
I think I almost find the solution, but still need someone's help.

The XML:
<?xml:stylesheet href="Style.xsl" type="text/xsl"?>
<source>
<m>1</m>
<m>2</m>
<n>
<a>one1</a>
<b>one2</b>
</n>
<n>
<a>two1</a>
<b>two2</b>
</n>
</source>

The XSL:
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<TABLE>
<xsl:for-each select="source/m">
<TR>
<TD>
<xsl:value-of select="."/>
</TD>
<TD>
<xsl:choose>
<xsl:when test="position()=1">
<xsl:value-of select="//n[1]/b"/>
</xsl:when>
<xsl:when test="position()=2">
<xsl:value-of select="//n[2]/b"/>
</xsl:when>
</xsl:choose>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>

The output:
1 one1
2 two1

However I think the solution is very stupid.
I would like to use the following way:

<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<TABLE>
<xsl:for-each select="source/m">
<TR>
<TD>
<xsl:value-of select="."/>
</TD>
<TD>
<xsl:value-of select="//n[position()]/b"/>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>

But the output is:
1 one1
2 one1

Can anyone know how it happen?

   
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.