xslt text with inline elements
Posted: Mon Jan 10, 2011 5:17 am
Hi, I have a layout program that can accommodate the following pattern:
<element1>text1<element2>text2<element2>text3<element1>
I'm assuming that text1 and text3 as text nodes are siblings of element2.
What I need to do is match element 1, create an output element with the value of its attribute, output the first text node, select element2, create an output element with the value of its attribute, and output the final text node, as if it were all one paragraph.
Here is the transform I've been working on:
I also tried using a choose/when (when the child of text:p is a text node, output the text node; when the child of text:p is an element, create a new element....
Argh, please help. What am I doing wrong? (neither Jeni nor Michael or Bob addresses this.)
<element1>text1<element2>text2<element2>text3<element1>
I'm assuming that text1 and text3 as text nodes are siblings of element2.
What I need to do is match element 1, create an output element with the value of its attribute, output the first text node, select element2, create an output element with the value of its attribute, and output the final text node, as if it were all one paragraph.
Here is the transform I've been working on:
Code: Select all
<xsl:template match="text:p">
<xsl:for-each select=".">
<xsl:element name="{@text:style-name}">
<xsl:value-of select="text()"/>
<xsl:apply-templates select="text:span"/>
</xsl:element>
</xsl:for-each>
</xsl:template>
<xsl:template name="text:span">
<xsl:element name="{@text:style-name}">
<xsl:value-of select="self::node()"/>
</xsl:element>
</xsl:template>
Argh, please help. What am I doing wrong? (neither Jeni nor Michael or Bob addresses this.)