xslt - How to parse "invalid" nested XML tags -


i'm trying construct xslt file xml file following, uses invalid nesting of tags:

<page>  <content>    <par>this content <i>contains</i> html <b><i>tags</i></b>.</par>    <par>this content <b>also</b> contains html <i><b>tags</b></i>.</par>  </content> </page> 

now if want output content new document, have this:

<xsl:template match="page/content">   <xsl:text disable-output-escaping="yes">&lt;![cdata[</xsl:text>   <xsl:for-each select="par">     <xsl:apply-templates select="."/>   </xsl:for-each>   <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text> </xsl:template>  <xsl:template match="par">   <p><xsl:value-of select="." /></p> </xsl:template>  <xsl:template match="b">   <strong><xsl:value-of select="." /></strong> </xsl:template>  <xsl:template match="i">   <em><xsl:value-of select="." /></em> </xsl:template> 

my question how need edit template match="par" <b> , <i> tags displayed correctly?

i've tried things like

<xsl:template match="par">   <p>   <xsl:apply-templates select="i"/>   <xsl:apply-templates select="b"/>   <xsl:value-of select="." /></p> </xsl:template> 

but results in incorrect order of output, because <i> , <b> tags displayed before complete paragraph. there possibility without changing format of original xml?

i don't see incorrectly nested tags in sample input i'm not sure mean that. xslt can't process incorrectly nested xml because it's not valid xml.

at rate, main problem xslt using value-of should using apply-templates:

<xsl:template match="page/content">   <xsl:text disable-output-escaping="yes">&lt;![cdata[</xsl:text>   <xsl:apply-templates select="par"/>   <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text> </xsl:template>  <xsl:template match="par">   <p><xsl:apply-templates /></p> </xsl:template>  <xsl:template match="b">   <strong><xsl:apply-templates /></strong> </xsl:template>  <xsl:template match="i">   <em><xsl:apply-templates /></em> </xsl:template> 

however, haven't shown output want i'm not sure solve issue.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -