...

View Full Version : Xml / Xsl



jeorg
11-28-2002, 06:00 PM
with this xml file

<conditions>
<titlePara>title 1</titlePara>
<para>para 10</para>
<titlePara>title 2</titlePara>
<para>para 20</para>
<para>para 21</para>
</conditions>

and this xsl file

<xsl:template match="/">
<xsl:for-each select="/conditions/titlePara">
<div class='title1'>
<xsl:value-of select="."/>
</div>
<xsl:for-each select="/conditions/para">
<div class='ParaNormal'>
<xsl:value-of select="."/>
</div>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

I get

title 1
para 10
para 20
para 21
title 2
para 10
para 20
para 21

how can I get

title 1
para 10
title 2
para 20
para 21

THANK YOU !

jkd
11-28-2002, 06:24 PM
Forgive my rusty XSLT, but in your first for-each loop, I believe you could do something like:

<xsl:if test="count(following-sibling::titlePara) &gt; 0">
<xsl:variable name="offset" select="position() + following-sibling::titlePara/position()"/>
</xsl:if>

Then maybe something like:

<xsl:for-each select="para">
<xsl:if test="position() &lt; $offset">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>

Inside the very first for-each.

This is all of the top of my head, and probably I made some errors, but it might be a start. :)

jeorg
11-28-2002, 06:43 PM
no I get an error !

it is so difficult to read this xml !

thanks anyway for helping

mpjbrennan
11-29-2002, 07:35 PM
Try this stylesheet:

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

<xsl:template match="/conditions/titlePara">
<div class='title1'>
<xsl:value-of select="."/>
</div>
</xsl:template>

<xsl:template match="/conditions/para">
<div class='ParaNormal'>
<xsl:value-of select="."/>
</div>
</xsl:template>

</xsl:stylesheet>


patrick

jeorg
11-30-2002, 08:03 AM
now I have a good idea , how it works

simple when you know it :-)


zhank you



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum