|
Subject: Re: [xsl] Transforming an XML document where the content isn't in a special tag From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx> Date: Wed, 17 Aug 2005 11:13:06 +0530 |
Below is a XSLT 2.0 stylesheet. I tested it with Saxon 8.4, but I got output
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<h1>
First Section
</h1>
<p>
This section deals with a lot of
</p>
<h1>
Second Section
</h1>
<p>
Now, this section is different, becase...
</p>
</body>
</html>
It seems Saxon does'nt seem to handle hetrogeneous sequence
following-sibling::text()[1] | a properly (I might be wrong..)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/root">
<html>
<head>
<title/>
</head>
<body>
<xsl:apply-templates select="header" />
</body>
</html>
</xsl:template>
<xsl:template match="header">
<h1><xsl:value-of select="." /></h1>
<xsl:call-template name="printTextNode">
<xsl:with-param name="nodelist"
select="following-sibling::text()[1] | a" />
</xsl:call-template>
</xsl:template>
<xsl:template name="printTextNode">
<xsl:param name="nodelist" />
<p>
<xsl:for-each select="$nodelist">
<xsl:choose>
<xsl:when test="name() = 'a'">
<xsl:copy-of select="." />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</p>
</xsl:template>
</xsl:stylesheet>
Regards,
Mukul
On 8/17/05, Noam Raphael <noamraph@xxxxxxxxx> wrote:
> Hello,
>
> I'm very new to XSL, so please forgive me if this question is stupid.
>
> I want to transform an XML document which looks like this:
>
> =====================
> <header>
> First Section
> </header>
> This section deals with a lot of <a href="bla.htm">things</a>.
> One of them, is...
>
> <header>
> Second Section
> </header>
> Now, this section is different, becase...
> =====================
>
> into this HTML:
>
> =====================
> <h1>First Section</h1>
> <p>This section deals with a lot of <a href="bla.htm">things</a>.
> One of them, is...</p>
> <h1>Second Section</h1>
> <p>Now, this section is different, bacause...</p>
> =====================
>
> I have a problem with adding the <p></p> tags. The problem is that
> their locations depends on the <header> tags. I can, of course, add a
> </p> before a header and a <p> after it, but I'll get an extra one at
> the beginning and at the end. Can I do this transformation with XSL?
> (If it matters, I used <xsl:for-each select="text() | *">)
>
> Thank you very much,
> Noam Raphael
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Transforming an XML document , Noam Raphael | Thread | Re: [xsl] Transforming an XML docum, Mukul Gandhi |
| [xsl] Transforming an XML document , Noam Raphael | Date | Re: [xsl] Transforming an XML docum, Mukul Gandhi |
| Month |