| Author |
multiple nodes of same name
|
|
| TheDude5B 2007-05-10, 6:16 pm |
| Hi,
I have an XML document which contains the node <gig> inside a <club>
node. There can be multiple <gig> nodes and the number is not the same
on all <club>'s
i.e.
<GLASGOW>
<venue>Glasgow</venue>
<address>Glasgow</address>
<url />
<gig>31st May 2007 - Shychild</gig>
<gig>2nd June 2007 - Broons</gig>
</GLASGOW>
Currently I am trying to display the XML document in an XSL document
like this
<?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:for-each select="/club/*">
<h3><xsl:apply-templates select="./venue" /></h3>
<h4><xsl:apply-templates select="./address" /></h4>
<p><font class="gigdate"><xsl:apply-templates select="./gig" /></font</
p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
however when the <gig> tags are displayed, they are displayed as one
line which is not what I want. I want to be able to add in a line
break <br /> after each <gig> node text.
Is there some way that this can be done?
Thanks
| |
| Martin Honnen 2007-05-10, 6:16 pm |
| TheDude5B wrote:
> I have an XML document which contains the node <gig> inside a <club>
> node. There can be multiple <gig> nodes and the number is not the same
> on all <club>'s
>
> i.e.
>
> <GLASGOW>
> <venue>Glasgow</venue>
> <address>Glasgow</address>
> <url />
> <gig>31st May 2007 - Shychild</gig>
> <gig>2nd June 2007 - Broons</gig>
> </GLASGOW>
So where is the club element or are the club elements?
> <p><font class="gigdate"><xsl:apply-templates select="./gig" /></font</
> p>
> however when the <gig> tags are displayed, they are displayed as one
> line which is not what I want. I want to be able to add in a line
> break <br /> after each <gig> node text.
<xsl:template match="gig">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">
<br/>
</xsl:if>
</xsl:template>
should help, that way, when you do xsl:apply-templates select="./gig"
the above template is used and outputs the text contents of the gig
element plus a br element, unless it is the last gig element.
Note that it makes more sense in this case to use a HTML ordered or
unordered list where each gig element is transformed in a li item element.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| |
| TheDude5B 2007-05-11, 6:18 am |
| That worked like a charm thanks.
Sorry I should have mentioned that the club element was the root
element like this.
<club>
<Glasgow>
<venue></venue>
<address></address>
<url></url>
<gig></gig>
</Glasgow>
<Aberdeen>
<venue></venue>
<address></address>
<url></url>
<gig></gig>
<gig></gig>
<gig></gig>
</Aberdeen>
<Newcastle>
<venue></venue>
<address></address>
<url></url>
<gig></gig>
<gig></gig>
</Newcastle>
</club>
|
|
|
|
| Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |