Subject: RE: [xsl] Mixed Content to flat, grouping query From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Mon, 21 Feb 2005 23:37:07 -0000 |
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.cole@xxxxxxxxxxx [mailto:chris.cole@xxxxxxxxxxx] > Sent: 21 February 2005 23:02 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Mixed Content to flat, groupi, chris.cole | Thread | RE: [xsl] Using XPATH axis within a, Pawson, David |
[xsl] Mixed Content to flat, groupi, chris.cole | Date | Re: [xsl] OT (browser standards), Mukul Gandhi |
Month |