On 2006-10-20,
gr************@gmail.com <gr************@gmail.comwrote:
[snip]
This works except that it places the new heading node in the wrong
place...
This is closer to what it actually looks like:
<notes>
<timestamp>
...
<content>
Here would be some <b><u>content...</u></b>
</content>
</timestamp>
<timestamp>
...
</timestamp>
</notes>
using your method results in:
<notes>
<timestamp>
...
<content>
<heading>content...</heading>
Here would be some <b><u>content...</u></b>
</content>
</timestamp>
<timestamp>
...
</timestamp>
</notes>
That is not the result that I get using xalan or saxon as the xlst
processor. Here are the files that I use.
input XML:
<?xml version="1.0"?>
<notes>
<timestamp>
...
<content>
Here would be some <b><u>content...</u></b>
</content>
</timestamp>
<timestamp>
...
</timestamp>
</notes>
XSLT (with a copy template in addition to the templates I suggested):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="u[parent::b]">
<heading>
<xsl:apply-templates select="node()"/>
</heading>
</xsl:template>
<xsl:template match="//b[u and count(node()) = 1]">
<xsl:apply-templates select="node()"/>
</xsl:template>
</xsl:stylesheet>
output:
<?xml version="1.0" encoding="UTF-8"?><notes>
<timestamp>
...
<content>
Here would be some <heading>content...</heading>
</content>
</timestamp>
<timestamp>
...
</timestamp>
Please provide a complete example that demonstrates the problem.
In one template I may have followed what you gave in your original
posting too closly by using 'match="//b[u and count(node()) = 1]'.
It would be better to use 'match="b[u and count(node()) = 1]'.