Jump to content
  • Advertisement
Sign in to follow this  
hplus0603

[web] XSLT for including the whole element?

This topic is 4334 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!