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
ina robisSubject: XSL:key for each condition - please help
Author: ina robis
Date: 20 Jul 2006 04:26 AM
Originally Posted: 20 Jul 2006 04:23 AM
Good Morning,

I am new to this forum and I have a problem with my xsl file. What I am trying to do it is to loop according to two keys.

I have this xml file

<?xml version="1.0"?>
<root>

<Rooms>

<Room>
<RommName>Suite</RommName>
<Informations>
<I>
<Currency>USD</Currency>
<Information>Internet</Information>
</I>
<price>
<A Date="31.07.2005"> 100</A>
<A Date="31.08.2005">411</A>
<A Date="30.09.2005">452</A>
<A Date="31.10.2005">452</A>
<B Date="31.07.2005">462</B>
<B Date="31.08.2005"> 125</B>
<B Date="30.09.2005">350</B>

</price>
</Informations>
</Room>
<Room>
<RommName>Little Suite</RommName>
<Informations>
<I>
<Currency>USD</Currency>
<Information>Internet</Information>
</I>
<price>
<A Date="30.04.2005"> 115</A>
<A Date="31.05.2005"> 115</A>
<A Date="30.06.2005"> 115</A>
<A Date="31.07.2005"> 115</A>
<A Date="31.08.2005">114</A>
<A Date="30.09.2005">115</A>
<B Date="31.08.2005">456</B>
<B Date="30.09.2005">456</B>
<B Date="31.10.2005"> 245</B>
<B Date="30.11.2005">250</B>
<B Date="31.12.2005">454</B>

</price>
</Informations>
</Room>

<Room>
<RommName>Suite 3</RommName>
<Informations>
<I>
<Currency>USD</Currency>
<Information>Internet</Information>
</I>
<price>
<A Date="31.12.2005"> 100</A>

</price>
</Informations>
</Room>
</Rooms>

</root>


and I have this kind of result, which is wrong
...
<TableRoom>
<ID>2</ID>
<Date>30.09.2005</Date>
<A>452</A>
<B>350</B>
<A>115</A>
<B>456</B>
</TableRoom>

....

The problem is that it is taking all value accross for one similar date appearing in price nodes for all roomName without distinction

What I would like it's something like this.
...
<TableRoom>
<ID>1</ID>
<Date>30.09.2005</Date>
<A>452</A>
<B>350</B>
</TableRoom>

<TableRoom>
<ID>2</ID>
<Date>30.09.2005</Date>
<A>115</A>
<B>456</B>
</TableRoom>

...

This is my xsl file
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="roomName" match="root/Rooms/Room/RoomName" use="generate-id()"/>
<xsl:key name="dates" match="@Date" use="."/>




<xsl:template match="/">
<TEST>
<xsl:for-each select="root/Rooms/Room">
<TableID>
<xsl:apply-templates select="root/Rooms/Room"/>
<xsl:variable name="vRowInd">
<xsl:number count="Room" level="any"/>
</xsl:variable>
<ID><xsl:param name="test" select="$vRowInd"/>
<xsl:value-of select="$test"/>


</ID>
<roomName>
<xsl:value-of select="RommName"/>
</roomName>
<Price>

<xsl:apply-templates select=""/>
</Price>
</TableID>
</xsl:for-each>

</TEST>
</xsl:template><!--<xsl:template match="root/Rooms/Room">

<xsl:variable name="vRowInd">
<xsl:number count="Room" level="any"/>
<xsl:param name="Id" select="$vRowInd"/>
</xsl:variable>
</xsl:template>-->
<xsl:template match="node()[not(descendant-or-self::price)] | @*">
<xsl:apply-templates/>
</xsl:template>

<xsl:template name="RoomName" match="root/Rooms/Room/roomName">
<xsl:param name="roomName" />
<xsl:for-each select="root/Rooms/Room/roomName">
<xsl:value-of select="$roomName" />
</xsl:for-each>
</xsl:template>

<xsl:template match="price">

<xsl:for-each select="*[count(key('roomName',/root/Rooms/Room/roomName)[1] | ./@Date ) = 1 ]">
<!--<xsl:for-each select="*[count(.|key('dates',@Date)[1] | ./root/Rooms/Room/roomName) = 1 ]">-->


<TableRoom>
<xsl:variable name="vRowInd">
<xsl:number count="Room" level="any"/>
</xsl:variable>
<ID>
<xsl:value-of select="$vRowInd"/>
</ID>
<Date>
<xsl:value-of select="@Date"/>
</Date>
<xsl:for-each select="key('dates', @Date)/parent::*"> <!-- problem here -->

<xsl:element name="{local-name()}">
<xsl:value-of select="."/>

</xsl:element>
</xsl:for-each>
</TableRoom>
</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

and how be able to pass the id between two templates?


thanks for your time

Ina

Postnext
Ivan PedruzziSubject: XSL:key for each condition - please help
Author: Ivan Pedruzzi
Date: 21 Jul 2006 11:44 PM

Ina,

Your stylesheet contains too many errors.

I suggest to read an online tutorial or read a good book like "XSLT Programmer's Reference"
http://www.amazon.com/gp/product/1861005067/002-4935165-9075263?v=glance&n=283155

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
ina robisSubject: XSL:key for each condition - please help
Author: ina robis
Date: 27 Jul 2006 05:55 AM
Thank you for your post... Which kind of errors.. Structure or xsl? I am new to xsl :) I have the book I will go through

Thanks again

Ina

Postnext
Ivan PedruzziSubject: XSL:key for each condition - please help
Author: Ivan Pedruzzi
Date: 27 Jul 2006 06:20 AM

Open your XSLT in Stylus Studio switch to Saxon 8.x then try to execute.

Once the synatx is fixed you may try to run the debugger step by step

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Posttop
ina robisSubject: XSL:key for each condition - please help
Author: ina robis
Date: 27 Jul 2006 06:34 AM
I did not run with saxon but with 'built-in' that's why I saw any error. Thanks I will do that.

Ina

 
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.