在XPath中,前缀不确定的属性名称始终被认为是在“no namespace”中。
因此,type
属性没有名称空间。
只需使用:
<xsl:template match="*[@type = 'xsd:string']">
...
</xsl:template>
当然,上述匹配模式不仅identityID
元件,但匹配任何元素的字符串值,其type
属性是'xsd:string'
。
UPDATE:该OP已“承认了注释”,他居然需要其type
属性指定在XML Schema命名空间的名称的任何元素匹配。
这是一个正确的解决方案(业务方案的解决方案仅适用于一个固定的前缀):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match=
"*[namespace::*
[name() = substring-before(../@type, ':')
and
. = 'http://www.w3.org/2001/XMLSchema'
]
]">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
这种转变相匹配的任何元素,其type
属性的值是在XML架构命名空间的名称 - 不管使用的前缀是!
当应用于,例如,在下面的XML文档:
<t xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<enitityID maxOccurs="0" minOccurs="0" type="xsd:string"/>
<somethingElse/>
<intIdID maxOccurs="0" minOccurs="0" type="xs:integer"/>
</t>
正确的结果(所有这些匹配元素复制到输出)产生:
<enitityID xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
maxOccurs="0" minOccurs="0" type="xsd:string"/>
<intIdID xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
maxOccurs="0" minOccurs="0" type="xs:integer"/>
我需要搭配其他XSD类型之外的xsd:字符串 – bretter 2012-02-29 15:23:51
答案是 的 您的评论让我看着办吧出。 –
bretter
2012-02-29 15:29:42
嘿,我正要编辑:) – Flynn1179 2012-02-29 16:03:28