【发布时间】:2014-09-09 05:48:19
【问题描述】:
我正在使用 XSLT 2.0 http://www.w3.org/TR/xslt20。我的 XSL 文件中有一个声明:
<xsl:template match="schema-attribute(attr)">
<match>schema-attribute(attr):</match>
</xsl:template>
我正在尝试将模式属性与 attr 匹配。我的 xml 文档中有多个 xml 元素,属性为 attr。
xml 文档:
<?xml version="1.0" encoding="UTF-8" ?>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noschemaLocation="http://www.w3.org/2001/XMLSchema-instance">
<e1>def</AAA>
<e1 attr="1">there</AAA>
<e1 attr="2">hey</AAA>
</test>
架构:
<?xml version="1.0" encoding="UTF-8" ?>
<x:schema xmlns:x="http://www.w3.org/2001/XMLSchema">
<x:element name="test" />
<x:element name="e1" type="etype" />
<x:complexType name="etype">
<x:simpleContent>
<x:extension base="x:string">
<x:attribute name="attr" type="x:string" use="optional"></x:attribute>
</x:extension>
</x:simpleContent>
</x:complexType>
xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0" >
<xsl:template match="schema-attribute(attr)">
<match>matched</match>
</xsl:template>
</xsl:stylesheet>
我收到以下错误:
序列类型表达式引用未在范围内属性声明中定义的架构属性“attr”。
我不知道错误的原因及其含义。我试图谷歌但没有找到解决方案。同样, attr 也是 xml 中的一个属性。
- 在此特定上下文中,范围内的属性声明意味着什么?
- 另外,如何使用上面的 xml 文件使用架构属性。
【问题讨论】:
-
您的 xml 仍然没有意义。
xsi:schemaLocation应该是命名空间/模式对的序列。由于您的文档不使用命名空间,因此您可能需要xsi:noNamespaceSchemaLocation。 -
好的,我做了这些更改。但是如何在这个 xml 文档中使用模式属性?
-
您是否只是想弄清楚如何匹配
attr属性?如果是这样,您的模板的匹配表达式将是<xsl:template match="@attr">。
标签: xml xslt xsd schema xslt-2.0