xslt - Store XML fragment into attribute as string using XSL -
i store fragment of xml attribute using xsl. example have following xml
<a> <b> <c>test1</c> <c>test2</c> </b> </a>
and have result (of cours xml in attribute should escaped properly):
<a attr="<b><c>test1</c><c>test2</c></b>"/>
is possible using xsl?
with xslt 3.0 there function serialize-xml
, in earlier versions can import module http://lenzconsulting.com/xml-to-string/ , code
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:import href="xml-to-string.xsl"/> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="a"> <xsl:copy> <xsl:attribute name="attr"> <xsl:apply-templates mode="xml-to-string"/> </xsl:attribute> </xsl:copy> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment