ial*_*ali 4 xml xslt namespaces
这可能是一个非常简单的问题,但它似乎无法得到它并且正在撕裂我的头发.我有以下XML:
<?xml-stylesheet type="text/xsl" href="email.xsl"?>
<Example xmlns="">
<Name xmlns="urn:rnb.fulfilment.bus.contracts.public.exampleBookName.v1">Mark</Name>
</Example>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下XSLT:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:template match="/">
<html>
<body>
<table width="90%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<p>AUTOMATED CONFIRMATION: This confirmation email is unable to take replies. For further assistance please visit our Help pages or Contact us</p>
<p>Dear <xsl:value-of select="Name"/>,</p>
<p>Thank you for blah blah... </p>
</td>
</tr>
</table>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
当我xmlns=urn:rnb.fulfilment.bus.contracts.public.exampleBookName.v1
在XML Feed中使用时,我无法显示名称,当我删除时xmlns
,名称显示正常.
我缺少一些语法吗?我已经尝试将命名空间添加到<xsl:stylesheet>
元素:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rpg="urn:rnb.fulfilment.bus.contracts.public.exampleBookName.v1"
>
Run Code Online (Sandbox Code Playgroud)
然后使用我在XPath表达式中给XSLT的前缀:
<xsl:value-of select="Name"/>
Run Code Online (Sandbox Code Playgroud)
但这也不起作用.有人可以帮忙吗?提前致谢.
声明命名空间的方法<xsl:stylesheet>
已经是正确的方向.现在你所要做的就是使用前缀:
<xsl:value-of select="Example/rpg:Name" />
Run Code Online (Sandbox Code Playgroud)
我进一步建议您对模板进行微小更改,以更好地反映您的输入:
<xsl:template match="Example">
<!-- ... -->
<xsl:value-of select="rpg:Name" />
</xsl:template>
Run Code Online (Sandbox Code Playgroud)