I'm using XSL Stylesheet version=3.0 and Saxon-PE 9.6.0.7, I'm getting the xml version="1.0" encoding="UTF-8" tags is coming along in JSON Output:
My Input xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<description>
<p>Here are some things other smokers say that they like about smoking:</p>
<ul>
<li>Smoking is a reward I can give myself when I finish a task.</li>
</ul>
</description>
XSL which i used as:
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:json="http://json.org/" xmlns:mf="http://example.com/mf" exclude-result-prefixes="#all">
<xsl:output omit-xml-declaration="yes" method="text"/>
<xsl:param name="length" as="xs:integer" select="80"/>
<xsl:param name="pattern" as="xs:string" select="concat('((.{1,', $length, '})( |$))')"/>
<xsl:param name="sep" as="xs:string" select="' + '"/>
<xsl:function name="mf:break" as="xs:string">
<xsl:param name="input" as="xs:string"/>
<xsl:variable name="result">
<xsl:analyze-string select="$input" regex="{$pattern}">
<xsl:matching-substring>
<xsl:value-of select="concat('', regex-group(2), '')"/>
<xsl:if test="position() ne last()">
<xsl:value-of select="$sep"/>
</xsl:if>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:sequence select="$result"/>
</xsl:function>
<xsl:template match="description">
"description": "<xsl:sequence select="mf:break(normalize-space(serialize(node())))"/>",
</xsl:template>
</xsl:stylesheet>
I'm getting the Json output as:
"description": "<?xml version="1.0" encoding="UTF-8"?><p>Here are some things other smokers say +
that they like about smoking:</p> <?xml version="1.0" encoding="UTF-8"?> +<ul><li>Smoking is a reward I can give myself when I finish a +
task.</li></ul>
But i need the output as:
"description": "<p>Here are some things other smokers say +
that they like about smoking:</p> <ul><li>Smoking is a +
reward I can give myself when I finish a +
task.</li></ul>
Why the xml version coming without I'm giving in the input. Please give me suggestion on this. Thanks in advance