Xml 尝试在xslt中仅检索一个节点值
你好,我有两个文件: Ej1.xml:Xml 尝试在xslt中仅检索一个节点值,xml,xslt,Xml,Xslt,你好,我有两个文件: Ej1.xml: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="prue1.xslt"?> <isa:ISAApplication xmlns:isa="http://xxxx"> <refId>olatesting</refId> <refId2>olatesting2<
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="prue1.xslt"?>
<isa:ISAApplication xmlns:isa="http://xxxx">
<refId>olatesting</refId>
<refId2>olatesting2</refId2>
</isa:ISAApplication>
prue1.xslt:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="ISAApplication">
<html>
<body>
<xsl:value-of select="/refId"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我正在尝试检索第一个refId,但它同时显示如下:
外侧刺外侧刺2
例如,您必须将isa名称空间添加到样式表声明中,并将前缀添加到模板匹配模式中
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:isa="http://xxxx" version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="isa">
<xsl:output omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>
<xsl:template match="isa:ISAApplication">
<xsl:value-of select="refId"/>
</xsl:template>
</xsl:stylesheet>
作为补充信息-之前,由于缺少名称空间,模板与输入XML根本不匹配-即使从XSL中删除模板,仍然会获得输入XML的两个值-
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>
</xsl:stylesheet>
但这可能取决于使用Saxon和Xalan测试的XSLT处理器
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>
</xsl:stylesheet>
olatesting
olatesting2