xsl duplicates data

1

1984to911

I have an XML of the form

<grandparent>
<top_element>
data
<special_element>special data</special_element>
</top_element>

<second_element>
<some_element>some data</some_element>
<special_element>other special data </special_element>
<some_other_element>some other data</some_other_element>
<second_element>
</grandparent>

I'm trying to get html output of the form

<div>
some data
<div>other special data </div>
some other data
</div>


so far the best I can get is
<div>
some data
other special data
some other data
<div>other special data</div>
</div>

by using
<xsl:template match="second_element">
<div><xsl:value-of select="."/>

<xsl:apply-templates select=".//special_element"/>
</div>
</xsl:template>

<xsl:template match="//second_element//special_element">
<div >
<xsl:value-of select="."/></div>
</xsl:template>
 
P

Pavel Lepin

<grandparent>
<top_element>
data
<special_element>special data</special_element>
</top_element>

<second_element>
<some_element>some data</some_element>
<special_element>other special data </special_element>
<some_other_element>some other data</some_other_element>
<second_element>

Not well-formed.
</grandparent>

I'm trying to get html output of the form

<div>
some data
<div>other special data </div>
some other data
</div>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates
select="grandparent/second_element"/>
</xsl:template>
<xsl:template match="second_element|special_element">
<xsl:element name="div">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top