XML 中的命名空间阻止正确的 XSL 执行
Namespace in XML prevents correct XSL execution
我的 XML 文件包含几个命名空间,这些命名空间阻止了我的 xsl 的正确执行。删除 xml 文件中的名称空间是使用 xsl 的唯一选项。但我想使用带有命名空间的原始 xml 文件。我应该如何操作我的 xsl 才能工作?
XML:
<?xml version="1.0" encoding="utf-8"?>
<SymbolLibrary xmlns="http://relaxng.org/ns/structure/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://relaxng.org/ns/structure/1.0
file:/D:/DevPool/MiStyle/Src/SymbolLibrary_1_0_0_1.xsd">
<IconComponents>
<IconComponent Id="10001">
<Name>PIK-PAR-Eiffelturm</Name>
<IconElems>
<BezierPolygon>
<ColorId>198</ColorId>
</BezierPolygon>
</IconElems>
</IconComponent>
<//IconComponents>
XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="IconComponent[@Id='10001']//ColorId/text()[.='210']">21</xsl:template>
</xsl:stylesheet>
有人可以给我提示吗?
"Prevent correct XSL execution" 是一个很好的措辞,但是你可能怀疑你的 xslt 没有告诉它正确地做
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:relax="http://relaxng.org/ns/structure/1.0">
<xsl:output omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>
然后将 relax: 添加到模板、选择和值中引用此类标签的所有位置(在您的输入中没有命名空间 xml)
请注意,这将为您提供带有命名空间 relax:
的输出
为避免这种情况,请使用
<xsl:template match="node()|@*">
<xsl:element name="local-name()">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
<xsl:template match="relax:IconComponent[@Id='10001']//relax:ColorId/text()[.='210']">21</xsl:template>
我的 XML 文件包含几个命名空间,这些命名空间阻止了我的 xsl 的正确执行。删除 xml 文件中的名称空间是使用 xsl 的唯一选项。但我想使用带有命名空间的原始 xml 文件。我应该如何操作我的 xsl 才能工作?
XML:
<?xml version="1.0" encoding="utf-8"?>
<SymbolLibrary xmlns="http://relaxng.org/ns/structure/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://relaxng.org/ns/structure/1.0
file:/D:/DevPool/MiStyle/Src/SymbolLibrary_1_0_0_1.xsd">
<IconComponents>
<IconComponent Id="10001">
<Name>PIK-PAR-Eiffelturm</Name>
<IconElems>
<BezierPolygon>
<ColorId>198</ColorId>
</BezierPolygon>
</IconElems>
</IconComponent>
<//IconComponents>
XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="IconComponent[@Id='10001']//ColorId/text()[.='210']">21</xsl:template>
</xsl:stylesheet>
有人可以给我提示吗?
"Prevent correct XSL execution" 是一个很好的措辞,但是你可能怀疑你的 xslt 没有告诉它正确地做
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:relax="http://relaxng.org/ns/structure/1.0">
<xsl:output omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>
然后将 relax: 添加到模板、选择和值中引用此类标签的所有位置(在您的输入中没有命名空间 xml)
请注意,这将为您提供带有命名空间 relax:
为避免这种情况,请使用
<xsl:template match="node()|@*">
<xsl:element name="local-name()">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
<xsl:template match="relax:IconComponent[@Id='10001']//relax:ColorId/text()[.='210']">21</xsl:template>