Either I've missed something, or you are making this much too complicated.
Where is the grouping?
You seem to simply need an identity transform with the addition of
<xsl:template match="content/text()">
<text><xsl:value-of select="."/></text>
</xsl:template>
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: chris(_dot_)cole(_at_)thomson(_dot_)com
[mailto:chris(_dot_)cole(_at_)thomson(_dot_)com]
Sent: 21 February 2005 23:02
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Mixed Content to flat, grouping query
Hello,
I have mixed content that I need to change to being all child
elements, so instead of:
INPUT:
<document> blah
<body> blah
<section>blah
<subsection>
<content>The primary contact is <variable name="fred" /> as
referred to in <link>section 2</link> of this document.</content>
<content>The cat sat on the mat.</content>
</subsection>
DESIRED OUTPUT:
<document> blah
<body> blah
<section>blah
<subsection>
<content><text>The primary contact is </text><variable name="fred"/>
<text> as referred to in </text><link>section 2</link><text>
of this document.</text>
</content>
<content><text>The cat sat on the mat.</text></content>
</subsection>
I thought I'd solved this problem using the XSL FAQ item on
Grouping Variants (thanks), but I could only achieve my
desired result while testing the data with the <subsection>
as the ROOT element, but this fragment is a long way down the
document tree, and when I tried to copy the rest of the
higher level hierarchy etc it all went wrong.
Can someone help me copy the rest of my document as it is and
only change this low-level mixed content please?
I'm sure it's not difficult, but i can't see the wood for the
trees anymore.
My current stylesheet is below.
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" />
<xsl:template match="subsection">
<subsection>
<xsl:apply-templates />
</subsection>
</xsl:template>
<xsl:template match="content">
<content>
<xsl:apply-templates select="node()[1]" />
</content>
</xsl:template>
<xsl:template match="link|variable">
<xsl:copy-of select="." />
<xsl:apply-templates select="following-sibling::node()[1]" />
</xsl:template>
<xsl:template match="*|text()">
<text>
<xsl:apply-templates select="." mode="copy" />
</text>
<xsl:apply-templates
select="following-sibling::*[self::variable or self::link][1]" />
</xsl:template>
<xsl:template match="*|text()" mode="copy">
<xsl:copy-of select="." />
<xsl:if test="not(following-sibling::node()[1]
[self::variable or self::link])">
<xsl:apply-templates
select="following-sibling::node()[1]" mode="copy" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Many thanks,
Chris
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--