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
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?

 
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.