This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Parsing mixed content nodes
- From: "Jason Macki" <jmacki at iisd dot ca>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 8 Feb 2002 15:32:19 -0600
- Subject: RE: [xsl] Parsing mixed content nodes
- Reply-to: xsl-list at lists dot mulberrytech dot com
The main thing was to extract the links from the a elements, and to
insert a new line where the br tag was.
I solved the problem this way:
<xsl:template name="textconvert">
<xsl:for-each select="node()">
<xsl:choose>
<xsl:when test="count(child::*) > 0">
<xsl:call-template name="textconvert" />
</xsl:when>
<xsl:when test="local-name(.)='br'">
<xsl:text>
</xsl:text>
</xsl:when>
<xsl:when test="local-name(.)='a'">
<xsl:value-of select="." /> (<xsl:value-of select="@href" />)
</xsl:when>
<xsl:when test="local-name(.)=''">
<xsl:value-of select="." />
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
The main problem was figuring out how to break up the pieces of a mixed
content node, and that can be done by doing a for-each select with the
node() function. It handles each type of tag by testing the local-name.
- Jason
-----Original Message-----
From: Thomas B. Passin [mailto:tpassin@mitretek.org]
Sent: Friday, February 08, 2002 3:06 PM
To: xsl-list@lists.mulberrytech.com
Subject: Re: [xsl] Parsing mixed content nodes
The big question is, do you want to handle any arbitrary mixed content,
or just <a> elements like this? If any, exactly what should be shown
for other elements, especially if they have more than one attribute?
Tom P
[Jason Macki]
I'm writing a stylesheet that converts some HTML code into text.
For example, this xml:
<item>
<p>
This is a <a href="link.htm">link</a><br />This is a new line. </p>
<item>
would be translated into this text:
This is a link(link.htm)
This is a new line.
I can use the descendant axis to retrieve the "p" node, the "a" node,
and the "br" node from the "item" element.
My problem is combining them back together, in the correct order.
I'd like to be able to write XSLT that would output:
"this is a", then the "a" node, then a line break for the "br" node, and
then output the remaining text.
Does anyone have any ideas?
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list