从XSL创建XSL

时间:2012-06-26 11:01:22

标签: xslt xslt-2.0

我正在尝试从XSLT样式表动态生成XSLT文档。当然,原则上这是有效的,但我没有让命名空间工作。我想让生成的XSLT元素以“xsl”前缀为前缀:

<xsl:stylesheet ...>

而不是

<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform">

我使用了xsl:element的namespace =“”和xsl:namespace,但是我没有使用它(xslt2 / saxon可用)

任何提示?

3 个答案:

答案 0 :(得分:3)

如果您想使用XSLT创建XSLT代码,那么使用http://www.w3.org/TR/xslt20/#element-namespace-alias会有所帮助。

<xsl:stylesheet
  version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:axsl="file://namespace.alias">

<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>

<xsl:template match="/">
  <axsl:stylesheet version="2.0">
    <xsl:apply-templates/>
  </axsl:stylesheet>
</xsl:template>

<xsl:template match="elements">
  <axsl:template match="/">
     <axsl:comment select="system-property('xsl:version')"/>
     <axsl:apply-templates/>
  </axsl:template>
</xsl:template>

<xsl:template match="block">
  <axsl:template match="{.}">
     <fo:block><axsl:apply-templates/></fo:block>
  </axsl:template>
</xsl:template>

</xsl:stylesheet>

答案 1 :(得分:1)

我找到了解决方案:

<xsl:element name="xsl:stylesheet">
</xsl:element>

完成这项工作! (即,避免使用namespace =“”但明确列出命名空间前缀)

答案 2 :(得分:1)

xsl:namespace-alias指令的设计正是考虑到这个用例 - 只需在工作中开始使用它。

这是一个真实的例子:

http://dnovatchev.wordpress.com/2006/10/21/a-stylesheet-to-write-xslt-code/

相关问题