The document is a valid and well formed finally even though i add
the tags in this manner </tag1><tag1>.
Regrouping the elements is not feasible in my situation as several
other things would be affected. I was hence wondering whether there
was any solution. If I use <xml:output> tag to show as "text". would
that work??
In XSLT there are no "starting tags" and "ending tags" ... only nodes,
that are atomic and cannot be broken in half.
One transformation that produces the result you need is the following:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/tag1">
<xsl:for-each select="tag2">
<xsl:variable name="vPrev" select="preceding-sibling::tag2[1]"/>
<xsl:variable name="vPastNodes"
select="count($vPrev/preceding-sibling::node())"/>
<xsl:variable name="vCurrentGroup"
select="preceding-sibling::node()
[count(preceding-sibling::node())
>=
$vPastNodes
]"/>
<tag1><xsl:copy-of select="$vCurrentGroup"/></tag1>
</xsl:for-each>
<tag1><xsl:copy-of select="tag2[last()]"/></tag1>
</xsl:template>
</xsl:stylesheet>
When applied on the source xml document provided by you:
<tag1>
data1
<tag2>data2</tag2>
data3
<tag2>data4</tag2>
<tag2>data5</tag2>
</tag1>
the result is:
<tag1>
data1
</tag1>
<tag1>
<tag2>data2</tag2>
data3
</tag1>
<tag1>
<tag2>data4</tag2>
</tag1>
<tag1>
<tag2>data5</tag2>
</tag1>
=====
Cheers,
Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
"Chandra -" <pchandramohan(_at_)hotmail(_dot_)com> wrote in message
news:F155dnjQ8vjqueolj8J000006d5(_at_)hotmail(_dot_)com(_dot_)(_dot_)(_dot_)
Hi Tom,
Thanks for the quick reply. Well for the tag structure you
mentioned
------
If you had a document like this, what should
the output look like?
<tag1>
data1
<tag2>data2</tag2>
data3
<tag2>data4</tag2>
<tag2>data5</tag2>
</tag1>
-----
the output should be
<tag1>
data1
</tag1><tag1>
<tag2>data2</tag2>
data3
</tag1><tag1>
<tag2>data4</tag2>
</tag1><tag1>
<tag2>data5</tag2>
</tag1>
You see the dtd states that "a <tag1> element can have a SINGLE
<tag2>
element as child provided <tag1> is IMMEDIATELY followed by <tag2>.
The document is a valid and well formed finally even though i add
the
tags in this manner </tag1><tag1>.
Regrouping the elements is not feasible in my situation as several
other
things would be affected. I was hence wondering whether there was any
solution. If I use <xml:output> tag to show as "text". would that
work??
Thanks in advance
Regards,
Chandra
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list