• Advertisement
Sign in to follow this  

[web] XSLT for including the whole element?

This topic is 4155 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement