I want to use XSLT to transform an XML into another XSLT. In the output XSLT, the namespace prefix and uri should be decided by the XML document. For example, the XML document is
<namespaces> <namespace> <prefix>abc</prefix> <uri>my.domain.abc</uri> </namespace> <namespace> <prefix>def</prefix> <uri>my.domain.def</uri> </namespace> </namespaces> And the output XSLT should be something like:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:abc="my.domain.abc" xmlns:def="my.domain.def" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"/> </xsl:stylesheet> I tried this way, it didn't work:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"> <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/> <xsl:template match="/"> <axsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:for-each select="/namespaces/namespace"> <xsl:namespace name="{prefix}" select="uri"/> </xsl:for-each> </axsl:stylesheet> </xsl:template> </xsl:stylesheet> The error is prefix: Missing context item. Any thought how to achieve this?
No comments:
Post a Comment