Sign in to follow this  
hplus0603

[web] XSLT for including the whole element?

Recommended Posts

I used to know this, but my age makes me forgetful, and Google is no help today. I have a document somewhat like:
<document>
  <section>
    <paragraph>
      Text goes here
    </paragraph>
    <table><tr><td>data</td><td>data</td></tr></table>
    <paragraph>
      More stuff
    </paragraph>
  </section>
</document>

Now, I have re-write rules for document, section, and paragraph that do the right thing. However, I'd like to include a rule for 'table' which includes the tag and sub-tags as-is. I've tride:
<xsl:template match='table'>
  <xsl:value-of select="."/>
</xsl:template>

However, this selects only the text, and doesn't actually output the tags.

Share this post


Link to post
Share on other sites
This is a somewhat tricky thing to do in XSLT. Try this:


<xsl:template match="table">
<xsl:apply-templates select="text() | *"/>
</xsl:template>

<xsl:template match="text() | * | @*">
<xsl:copy>
<xsl:apply-templates select="text() | * | @*"/>
</xsl:copy>
</xsl:template>



It should preserve everything under "table", tags and all.

Hope this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this