473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Problem with XSLT transfromation

Hi,

I have a question regarding XSLT . Is it possible to output elements
in an XML between two values.
Here is an XML example of my data :

<root>
<stations>
<station>
<name>A</name>
<dep>05:25</dep>
<pos>1</pos>
<id>56</id>
</station>
<station>
<name>B</name>
<dep>06:25</dep>
<pos>2</pos>
<id>35</id>
</station>
<station>
<name>c</name>
<dep>07:25</dep>
<pos>3</pos>
<id>78</id>
</station>
<station>
<name>D</name>
<dep>08:25</dep>
<pos>4</pos>
<id>134</id>
</station>
****
****

</stations>
<start_station>
<id>35</id>
</start_station>
<end_station>
<id>78</id>
</end_station>
</root>

My aim si to output all those <station> elements that are between
<start_station><id> and
<end_station><id> values. I tried with <xsl:variable> but it did not
work.
Any help will be very apriciated.

Thank you,

Boris
Jul 20 '05 #1
6 1282
> My aim si to output all those <station> elements that are between
<start_station><id> and
<end_station><id> values.

Hi,
A stylesheet like this will do the trick:

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

<xsl:template match="stations">
<stations>
<xsl:apply-templates select="station[id &gt; //start_station/id and id &lt; //end_station/id]"/>
</stations>
</xsl:template>

<xsl:template match="station">
<xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2
Hi Joris,

The problem is that id's are not sorted numbers and so start_id could be
175 and end_id = 17. The position of a station is defined with the <pos>
element and they are sorted by <pos>. I was trying to set a variable
with the <pos> value where start_station/id = stations/station/id but i
can't quit do that...is it posible to make such a variable in tghis way
and then use it?

<xsl:for-each select="stations/station">
<xsl:if test="id = ../../start_station_id">
<xsl:variable name="sid" select="id"/>
</xsl:if>
</xsl:for-each>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
> The problem is that id's are not sorted numbers and so start_id could be
175 and end_id = 17. The problem is solved with this:

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

<xsl:variable name="start_id">
<xsl:value-of select="//start_station[id &lt; //end_station/id]"/>
<xsl:value-of select="//end_station[id &lt; //start_station/id]"/>
</xsl:variable>

<xsl:variable name="end_id">
<xsl:value-of select="//start_station[id &gt; //end_station/id]"/>
<xsl:value-of select="//end_station[id &gt; //start_station/id]"/>
</xsl:variable>

<xsl:template match="stations">
<stations>
<xsl:apply-templates select="station[id &gt; $start_id and id &lt; $end_id]"/>
</stations>
</xsl:template>

<xsl:template match="station">
<xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>

The position of a station is defined with the <pos>
element and they are sorted by <pos>. I was trying to set a variable
with the <pos> value where start_station/id = stations/station/id but i
can't quit do that...is it posible to make such a variable in tghis way
and then use it?


I don't understand what could be the use, but the code would be:

<xsl:for-each select="stations/station">
<xsl:variable name="sid">
<xsl:if test="id = ../../start_station/id">
<xsl:value-of select="id"/>
</xsl:if>
</xsl:variable>
</xsl:for-each>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #4
Hi Joris,

Thank you for your extensive help, it helps me a lot, but it doesn't
solve my problem.
Maybe I wasn't very clear in my previous post.

An XML Example:
<train>
<stations>
<station>
<pos>0</pos>
<id>65</id>
</station>
<station>
<pos>1</pos>
<id>32</id>
</station>
<station>
<pos>2</pos>
<id>117</id>
</station>
<station>
<pos>3</pos>
<id>4</id>
</station>
<station>
<pos>4</pos>
<id>18</id>
</station>
<station>
<pos>5</pos>
<id>100</id>
</station>
</stations>
<start_station>
<id>117</id>
</start_station>
<end_station>
<id>18</id>
</end_station>
<traindata>...
<train>

In the output i need to get the following stations in the order that
they are in the XML file..

<station>
<pos>2</pos>
<id>117</id>
</station>
<station>
<pos>3</pos>
<id>4</id>
</station>
<station>
<pos>4</pos>
<id>18</id>
</station>
Maybe I'm not getting your solution right ?

With best regards ,

Boris
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5
> Thank you for your extensive help, it helps me a lot, but it doesn't
solve my problem.
Maybe I wasn't very clear in my previous post.

Ooh, I understand, interpreted your question totally wrong:)

You could probably use something like this:

<xsl:variable name="start_station_pos">
<xsl:value-of select="//station[id = //start_station/id]/pos"/>
</xsl:variable>

<xsl:variable name="end_station_pos">
<xsl:value-of select="//station[id = //end_station/id]/pos"/>
</xsl:variable>

<xsl:template match="stations">
<stations>
<xsl:apply-templates select="station[pos &gt;= $start_station_pos and pos &lt;= $end_station_pos]"/>
</stations>
</xsl:template>
I hope I finally got it right...

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #6

Hi, Joris,

Thank you very much.
This works like a chadrm.

With best regards,
Boris
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
4
by: Trygve | last post by:
I'm trying to convert a XML-document using XSLT. Depending on the source file (the XML-document) the conversion is either correct or incorrect. If the first tag in the document contains an non...
4
by: fis | last post by:
Hi all, I've problem because there are needed break lines in my texts on the web site but i can't do it :( My pipeline looks like: XMS -> I18N -> XSLT -> HTML I have lot of texts in my...
0
by: Mike | last post by:
I'm generating an XSLT document programatically in VB.Net. I'm then trying to apply that XSLT against a cXML document to generate my own internally developed XML document. I'm using RichTextBox...
2
by: chris | last post by:
Hi there, I create an XML file from a dataset like this: System.IO.StreamWriter xmlSW = new System.IO.StreamWriter(FILENAME); dsUserData1.WriteXml(xmlSW, XmlWriteMode.WriteSchema);...
2
by: Pawel | last post by:
I have small problem with XslTransformation. I get from WebService xml document. I have xslt and I want transform xml document to html code. It's look easy but I cant't manage with xPath. Maybe...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
6
by: Christoph | last post by:
I'm trying to come up with a stylesheet where, when the rows are displayed, duplicate game names are not shown on subsequent rows. It works but doesn't work properly. If I sort the data using...
1
by: balderdash | last post by:
Hi I am very close to achieving the output I need but I cant seem to get it right. The problem is I am looping through a table and selecting values, if there are 2 values per (row) Issuer I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.