473,508 Members | 3,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xsl subsets of nodesets

HOpe you can help with this...

I have the following xml document...

<?xml version="1.0" ?>
<file>
<header>some data</header>
<detail> some more data</detail>
<footer> gdshada </footer>

<header>some data</header>
<detail> some more data</detail>
<detail> some more data</detail>
<detail> some more data</detail>
<footer> gdshada </footer>

<header>some data</header>
<detail> some more data</detail>
<detail> some more data</detail>
<footer> gdshada </footer>
</file>
I am using xslt to process these header detail records.
The question is how can i select the subsets of detail tags in turn
for processing as they are on the same level in terms of hierachy

I would maybe like to do something similar to ..

<xsl:for-each select="following::DETAIL[position() &gt;=
$header_position and position() &lt;= $footer_position]">

.... but how can i determine the header and footer position?

Thanks for any help..

Will
Jul 20 '05 #1
3 2061
Hi Will,

So you can see which <detail> and <footer> elements are getting pushed....

== XML ==========================================
<?xml version="1.0"?>
<file>
<header>h1</header>
<detail>d1</detail>
<footer>f1</footer>

<header>h2</header>
<detail>d2.1</detail>
<detail>d2.2</detail>
<detail>d2.3</detail>
<footer>f2</footer>

<header>h3</header>
<detail>d3.1</detail>
<detail>d3.2</detail>
<footer>f3</footer>
</file>
== end of XML ===================================

Try something like...

== XSL ==========================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="file">
<html>
<body>
<xsl:apply-templates select="header"/>
</body>
</html>
</xsl:template>

<xsl:template match="header">
<h3>
<xsl:value-of select="."/>
</h3>
<!-- apply to all details and footers that follow this header -->
<xsl:apply-templates select="(following-sibling::detail |
following-sibling::footer)[generate-id(preceding-sibling::header[1]) =
generate-id(current())]"/>
</xsl:template>

<xsl:template match="detail">
<div>
<xsl:value-of select="."/>
</div>
</xsl:template>

<xsl:template match="footer">
<div style="font-style: italic; font-size: small;">
<xsl:text>(footer: </xsl:text>
<xsl:value-of select="."/>
<xsl:text>)</xsl:text>
</div>
</xsl:template>
</xsl:stylesheet>
== end of XSL ===================================

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"will" <wi***********@hotmail.com> wrote in message
news:28**************************@posting.google.c om...
HOpe you can help with this...

I have the following xml document...

<?xml version="1.0" ?>
<file>
<header>some data</header>
<detail> some more data</detail>
<footer> gdshada </footer>

<header>some data</header>
<detail> some more data</detail>
<detail> some more data</detail>
<detail> some more data</detail>
<footer> gdshada </footer>

<header>some data</header>
<detail> some more data</detail>
<detail> some more data</detail>
<footer> gdshada </footer>
</file>
I am using xslt to process these header detail records.
The question is how can i select the subsets of detail tags in turn
for processing as they are on the same level in terms of hierachy

I would maybe like to do something similar to ..

<xsl:for-each select="following::DETAIL[position() &gt;=
$header_position and position() &lt;= $footer_position]">

... but how can i determine the header and footer position?

Thanks for any help..

Will

Jul 20 '05 #2
That looks pretty good thanks marrow, but it needs to be taken a bit
further

I need to pass the name of the header into its corresponding details
somehow. So for the xml/xslt you describe below we could have the
following result...

<html>
<body>
<h3>header1</h3>
<div>detail 1 belongs to header 1</div>
<div style="font-style: italic; font-size: small;">(footer:
f1)</div>
<h3>header2</h3>
<div>detail 1 belongs to header 2</div>
<div>detail 2 belongs to header 2</div>
<div>detail 3 belongs to header 2</div>
<div style="font-style: italic; font-size: small;">(footer:
f2)</div>
<h3>header3</h3>
<div>detail 1 belongs to header 3</div>
<div>detail 2 belongs to header 3</div>
<div style="font-style: italic; font-size: small;">(footer:
f3)</div>
</body>
</html>
with the detail tags saying which header they "belong" to..

thanks agian for your help..
"Marrow" <marrow-NO-@-SPAM-marrowsoft.com> wrote in message news:<g4***************@newsfep3-gui.server.ntli.net>...
Hi Will,

So you can see which <detail> and <footer> elements are getting pushed....

== XML ==========================================
<?xml version="1.0"?>
<file>
<header>h1</header>
<detail>d1</detail>
<footer>f1</footer>

<header>h2</header>
<detail>d2.1</detail>
<detail>d2.2</detail>
<detail>d2.3</detail>
<footer>f2</footer>

<header>h3</header>
<detail>d3.1</detail>
<detail>d3.2</detail>
<footer>f3</footer>
</file>
== end of XML ===================================

Try something like...

== XSL ==========================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="file">
<html>
<body>
<xsl:apply-templates select="header"/>
</body>
</html>
</xsl:template>

<xsl:template match="header">
<h3>
<xsl:value-of select="."/>
</h3>
<!-- apply to all details and footers that follow this header -->
<xsl:apply-templates select="(following-sibling::detail |
following-sibling::footer)[generate-id(preceding-sibling::header[1]) =
generate-id(current())]"/>
</xsl:template>

<xsl:template match="detail">
<div>
<xsl:value-of select="."/>
</div>
</xsl:template>

<xsl:template match="footer">
<div style="font-style: italic; font-size: small;">
<xsl:text>(footer: </xsl:text>
<xsl:value-of select="."/>
<xsl:text>)</xsl:text>
</div>
</xsl:template>
</xsl:stylesheet>
== end of XSL ===================================

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"will" <wi***********@hotmail.com> wrote in message
news:28**************************@posting.google.c om...
HOpe you can help with this...

I have the following xml document...

<?xml version="1.0" ?>
<file>
<header>some data</header>
<detail> some more data</detail>
<footer> gdshada </footer>

<header>some data</header>
<detail> some more data</detail>
<detail> some more data</detail>
<detail> some more data</detail>
<footer> gdshada </footer>

<header>some data</header>
<detail> some more data</detail>
<detail> some more data</detail>
<footer> gdshada </footer>
</file>
I am using xslt to process these header detail records.
The question is how can i select the subsets of detail tags in turn
for processing as they are on the same level in terms of hierachy

I would maybe like to do something similar to ..

<xsl:for-each select="following::DETAIL[position() &gt;=
$header_position and position() &lt;= $footer_position]">

... but how can i determine the header and footer position?

Thanks for any help..

Will

Jul 20 '05 #3
Hi Will,

The easiest way would be pass the <header> node as param to the templates as
they are applied, e.g.

== XSL1 ==========================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="file">
<html>
<body>
<xsl:apply-templates select="header"/>
</body>
</html>
</xsl:template>

<xsl:template match="header">
<h3>
<xsl:value-of select="."/>
</h3>
<!-- apply to all details and footers that follow this header -->
<xsl:apply-templates select="(following-sibling::detail |
following-sibling::footer)[generate-id(preceding-sibling::header[1]) =
generate-id(current())]">
<xsl:with-param name="hdr" select="."/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="detail">
<xsl:param name="hdr"/>
<div>
<xsl:value-of select="."/>
<xsl:text> belongs to </xsl:text>
<xsl:value-of select="$hdr"/>
</div>
</xsl:template>

<xsl:template match="footer">
<xsl:param name="hdr"/>
<div style="font-style: italic; font-size: small;">
<xsl:text>(footer: </xsl:text>
<xsl:value-of select="."/>
<xsl:text> belongs to </xsl:text>
<xsl:value-of select="$hdr"/>
<xsl:text>)</xsl:text>
</div>
</xsl:template>
</xsl:stylesheet>
== end of XSL1 ===================================

Alternatively you could always get hold of the preceding <header> for each
<detail> and <footer> quite easily, e.g.

== XSL2 ==========================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="file">
<html>
<body>
<xsl:apply-templates select="header"/>
</body>
</html>
</xsl:template>

<xsl:template match="header">
<h3>
<xsl:value-of select="."/>
</h3>
<!-- apply to all details and footers that follow this header -->
<xsl:apply-templates select="(following-sibling::detail |
following-sibling::footer)[generate-id(preceding-sibling::header[1]) =
generate-id(current())]"/>
</xsl:template>

<xsl:template match="detail">
<div>
<xsl:value-of select="."/>
<xsl:text> belongs to </xsl:text>
<xsl:value-of select="preceding-sibling::header[1]"/>
</div>
</xsl:template>

<xsl:template match="footer">
<div style="font-style: italic; font-size: small;">
<xsl:text>(footer: </xsl:text>
<xsl:value-of select="."/>
<xsl:text> belongs to </xsl:text>
<xsl:value-of select="preceding-sibling::header[1]"/>
<xsl:text>)</xsl:text>
</div>
</xsl:template>
</xsl:stylesheet>
== end of XSL2 ===================================
Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"will" <wi***********@hotmail.com> wrote in message
news:28**************************@posting.google.c om...
That looks pretty good thanks marrow, but it needs to be taken a bit
further

I need to pass the name of the header into its corresponding details
somehow. So for the xml/xslt you describe below we could have the
following result...

<html>
<body>
<h3>header1</h3>
<div>detail 1 belongs to header 1</div>
<div style="font-style: italic; font-size: small;">(footer:
f1)</div>
<h3>header2</h3>
<div>detail 1 belongs to header 2</div>
<div>detail 2 belongs to header 2</div>
<div>detail 3 belongs to header 2</div>
<div style="font-style: italic; font-size: small;">(footer:
f2)</div>
<h3>header3</h3>
<div>detail 1 belongs to header 3</div>
<div>detail 2 belongs to header 3</div>
<div style="font-style: italic; font-size: small;">(footer:
f3)</div>
</body>
</html>
with the detail tags saying which header they "belong" to..

thanks agian for your help..
"Marrow" <marrow-NO-@-SPAM-marrowsoft.com> wrote in message

news:<g4***************@newsfep3-gui.server.ntli.net>...
Hi Will,

So you can see which <detail> and <footer> elements are getting pushed....
== XML ==========================================
<?xml version="1.0"?>
<file>
<header>h1</header>
<detail>d1</detail>
<footer>f1</footer>

<header>h2</header>
<detail>d2.1</detail>
<detail>d2.2</detail>
<detail>d2.3</detail>
<footer>f2</footer>

<header>h3</header>
<detail>d3.1</detail>
<detail>d3.2</detail>
<footer>f3</footer>
</file>
== end of XML ===================================

Try something like...

== XSL ==========================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="file">
<html>
<body>
<xsl:apply-templates select="header"/>
</body>
</html>
</xsl:template>

<xsl:template match="header">
<h3>
<xsl:value-of select="."/>
</h3>
<!-- apply to all details and footers that follow this header -->
<xsl:apply-templates select="(following-sibling::detail |
following-sibling::footer)[generate-id(preceding-sibling::header[1]) =
generate-id(current())]"/>
</xsl:template>

<xsl:template match="detail">
<div>
<xsl:value-of select="."/>
</div>
</xsl:template>

<xsl:template match="footer">
<div style="font-style: italic; font-size: small;">
<xsl:text>(footer: </xsl:text>
<xsl:value-of select="."/>
<xsl:text>)</xsl:text>
</div>
</xsl:template>
</xsl:stylesheet>
== end of XSL ===================================

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"will" <wi***********@hotmail.com> wrote in message
news:28**************************@posting.google.c om...
HOpe you can help with this...

I have the following xml document...

<?xml version="1.0" ?>
<file>
<header>some data</header>
<detail> some more data</detail>
<footer> gdshada </footer>

<header>some data</header>
<detail> some more data</detail>
<detail> some more data</detail>
<detail> some more data</detail>
<footer> gdshada </footer>

<header>some data</header>
<detail> some more data</detail>
<detail> some more data</detail>
<footer> gdshada </footer>
</file>
I am using xslt to process these header detail records.
The question is how can i select the subsets of detail tags in turn
for processing as they are on the same level in terms of hierachy

I would maybe like to do something similar to ..

<xsl:for-each select="following::DETAIL[position() &gt;=
$header_position and position() &lt;= $footer_position]">

... but how can i determine the header and footer position?

Thanks for any help..

Will

Jul 20 '05 #4

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

Similar topics

3
7513
by: Simon | last post by:
Hi, I'm hoping you could show me examples of how a functional/declarative language could be used to consicely describe resticted subsets of elements. I'm looking for a 'specification' style...
4
1931
by: Brett Calcott | last post by:
I've found some python solutions to find the set of subsets for a given set, but how do you find the set of the set of subsets whose union is the given set and whose intersections is the empty set....
2
1349
by: cdiggins | last post by:
I am familiar with TinyXML and "Simple XML Subset Parser" from GLib, but I was wondering if there exist any specifications subsets of XML without attributes? I proposed one called XML-- (XML minus...
7
8863
by: Gaijinco | last post by:
I been thinking about this topic for a long time. The best I have done is the following code: #include <iostream> using namespace std; #include <cmath> int main(){ const int SIZE=3;
25
5835
by: Jessica Weiner | last post by:
I have an array of n integers and I want a function that returns a list of arrays of all possible subsets. Can someone provide me with the code? Thanks. Jess
4
1674
by: LurfysMa | last post by:
I could use some help with a table design problem. I have an electronic flashcard program. Actually, several of them. They each rely on a utility program to keep track of the usage statistics....
3
1736
by: Lord0 | last post by:
I *think* I need to be able to validate subsets of an XML document using different schema. The functionality I'm trying to implement is this. a) External suppliers produce an XML document...
4
3598
by: Patrick | last post by:
Hi, I want to write a programs that checks if a set of numbers in a list obey a condition, the problem is that i have say "n" numbers and i need to check all subsets of the n numbers for the...
1
3812
by: Rajesh V | last post by:
Hi, The aim of this C++ code is to print all the k-element subsets of a set of size n. But somewhere it goes wrong - it doesn't print the answer properly. I tried a lot to find the mistake, but...
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7128
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
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7502
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...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.