Given the XSL template and XML below, here’s the HTML output i’m trying to achieve (more or less):
<p>
foo goes here
<span class="content"><p>blah blah blah</p><p>blah blah blah</p></span>
bar goes here
<span class="content">blah blah blah blah blah blah</span>
</p>
Here is what is actually getting rendered (entire contents of <span.content> missing):
<p>
foo goes here
<span class="content"></span>
bar goes here
<span class="content">blah blah blah blah blah blah</span>
</p>
Here’s my template (snippet):
<xsl:template match="note[@type='editorial']">
<span class="content">
<xsl:apply-templates />
</span>
</xsl>
<xsl:template match="p">
<p>
<xsl:apply-templates />
</p>
</xsl>
Here’s my xml:
<p>
foo goes here
<note type="editorial"><p>blah blah blah</p><p>blah blah blah</p></note>
bar goes here
<note type="editorial">blah blah blah blah blah blah</note>
</p>
Rendering particular elements is not important. ie. I don’t care whether a <p> or <div> or <span> gets rendered, so long as none of the text elements are lost.
I would like to avoid creating a specific rule to match “p/note/p”, assuming that a <note> element can contain any arbitrary children.
I’m a total noob to xsl, so any additional tips or pointers would be really helpful.
Thanks in advance.
OK, so I’m just fussing around and here’s the solution i finally came up with.
Nested <p> tags just don’t work. Your browser doesn’t like them, and XSLT doesn’t like them either. So, I switched everything to <divs> and <spans>
Also, I added a couple catch-all templates to the end of my template.
Here’s the final version that’s working well enough for my purposes:
h/t:
http://www.dpawson.co.uk/xsl/sect2/defaultrule.html
and How can xsl:apply-templates match only templates I have defined?