XSL和命名空间 [英] XSL and Namespaces
问题描述
这可能是一个非常简单的问题,但是我似乎无法理解并且正在扯掉我的头发.我有以下XML:
This may be a really simple question, but its one I can't seem to get and am tearing my hair out over. I have the following XML:
<?xml-stylesheet type="text/xsl" href="email.xsl"?>
<Example xmlns="">
<Name xmlns="urn:rnb.fulfilment.bus.contracts.public.exampleBookName.v1">Mark</Name>
</Example>
并且正在尝试使用以下XSLT:
And am trying to use the following 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>
当我在XML提要中使用xmlns=urn:rnb.fulfilment.bus.contracts.public.exampleBookName.v1
时,无法显示名称.当删除xmlns
时,该名称显示正常.
I cannot get the Name to appear when I am using the xmlns=urn:rnb.fulfilment.bus.contracts.public.exampleBookName.v1
in the XML feed, when I remove the xmlns
, the name displays fine.
我缺少一些语法吗?我尝试将名称空间添加到<xsl:stylesheet>
元素:
Is there some syntax I'm missing? I've tried adding the namespace to the <xsl:stylesheet>
element:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rpg="urn:rnb.fulfilment.bus.contracts.public.exampleBookName.v1"
>
然后使用我在XPath表达式中为XSLT赋予的前缀:
Then using the prefix I gave to the XSLT in the XPath expression:
<xsl:value-of select="Name"/>
但这也不起作用.有人可以帮忙吗?预先感谢.
But this doesn't work either. Can anyone help? Thanks in advance.
推荐答案
或者使用谓词和local-name().例如:
Alternatively use a predicate and local-name(). E.g.:
<xsl:value-of select="*[local-name() = 'Name']"/>
这篇关于XSL和命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!