I have an XML document similar to:
<tag>
<content>adsfasdf<b>asdf</b></content>
</tag>
I would like for the XSLT to select the content element and show all of the content:
<xsl:value-of select="/tag/content"/>
The XSLT is configured to render as HTML. Is there a way that I can get the value-of/copy-of to display the exact content without having to render it?
What I'm looking for is
asdfasdf<b>asdf</b>
And not:
asdfasdf asdf
Create an XSL stylesheet.xml version=”1.0″?> To bind the XML elements to a HTML table, the <for-each> XSL template must appear before each table row tag. This ensures that a new row is created for each <book> element. The <value-of> template will output the selected text of each child element into a separate table.
The standard way to transform XML data into other formats is by Extensible Stylesheet Language Transformations (XSLT). You can use the built-in XSLTRANSFORM function to convert XML documents into HTML, plain text, or different XML schemas. XSLT uses stylesheets to convert XML into other data formats.
You can generate HTML documentation from an XML Schema file. The HTML documentation contains various information about the message model that is included in the XML Schema file. This documentation can be useful for providing a summary of the contents of your XML Schema file.
With XSLT you can transform an XML document into HTML.
You need to escape the tag names within the content, I'd recommend something like:
<xsl:template match="content//*">
<xsl:value-of select="concat('<',name(),'>')"/>
<xsl:apply-templates/>
<xsl:value-of select="concat('</',name(),'>')"/>
</xsl:template>
which you then can call with:
<xsl:apply-templates select="/tag/content"/>
Quick and dirty way:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="content">
<xsl:copy-of select="text() | *"/>
</xsl:template>
</xsl:stylesheet>
Result against your sample will be:
adsfasdf<b>asdf</b>
Another approach:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="b">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With