【问题标题】:remove namespace prefix with xslt使用 xslt 删除命名空间前缀
【发布时间】:2013-11-28 12:51:29
【问题描述】:

我正在尝试从外部 xsd 文件中检索类型定义。在这个例子中,我的$attType 有一个命名空间前缀。但是在我用来获取定义的 XPath 中,我不需要前缀。 问题是:如何?

<xsl:copy-of select="document('../file.xsd')//xs:simpleType[@name=$attType]" />

【问题讨论】:

标签: xml xslt xpath


【解决方案1】:

一个稍微不那么脏的解决方案是使用local-name() 来正确确定命名空间内的对象名称。

这应该从元素和属性中去除命名空间,并保留文本:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="@*">
    <xsl:attribute name="{local-name(.)}">
      <xsl:value-of select="." />
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="node()">
    <xsl:element name="{local-name(.)}">
      <xsl:apply-templates select="@*|*|text()"/>
    </xsl:element>
  </xsl:template>
  <xsl:template match="text()">
      <xsl:copy />
  </xsl:template>
</xsl:stylesheet>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多