xslt - How to load > & lt in to another xml using xslt2.0? -
input xml
<note> <from>example</from> <heading>reminder</heading> <body>xslt conversion</body> </note>
output xml expected.
<xml> <data> <column1> <note> <from>example</from> <heading>reminder</heading> <body>xslt conversion</body> </note> </column1> </data> </xml>
current xslt using have issues loading input. (if input straight xml not have issue copying it, encoded xml).
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0"> <xsl:template match="/"> <xml> <data> <column1> <xsl:copy> <xsl:copy-of select="/node()"/> </xsl:copy> </column1> </data> </xml> </xsl:template> </xsl:stylesheet>
since you're using xslt 2.0, can use unparsed-text()
process input. if pass path text file parameter, can use either text or xml input same stylesheet.
- if input text, pass path text file parameter. still have pass xml stylesheet, can use stylesheet input.
- if input xml, don't pass value parameter.
input (test.txt)
<note> <from>example</from> <heading>reminder</heading> <body>xslt conversion</body> </note>
xslt 2.0 (using stylesheet xml input , passing test.txt
input
param)
<xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:xsl="http://www.w3.org/1999/xsl/transform" exclude-result-prefixes="xs"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:param name="input" select="''" as="xs:string"/> <xsl:template match="/"> <xml> <data> <column1> <xsl:choose> <xsl:when test="$input"> <xsl:copy-of select="unparsed-text($input)"/> </xsl:when> <xsl:otherwise> <xsl:copy-of select="*"/> </xsl:otherwise> </xsl:choose> </column1> </data> </xml> </xsl:template> </xsl:stylesheet>
output
<xml> <data> <column1>&lt;note&gt; &lt;from&gt;example&lt;/from&gt; &lt;heading&gt;reminder&lt;/heading&gt; &lt;body&gt;xslt conversion&lt;/body&gt; &lt;/note&gt; </column1> </data> </xml>
Comments
Post a Comment