Xml xslt在根元素中无法按预期工作
我有如下xmlXml xslt在根元素中无法按预期工作,xml,xslt,xpath,Xml,Xslt,Xpath,我有如下xml <pin> <securityProfile> <userName>userName</userName> </securityProfile> </pin> 用户名 预期产量 <user_id> <userName>userName</userName> &l
<pin>
<securityProfile>
<userName>userName</userName>
</securityProfile>
</pin>
用户名
预期产量
<user_id>
<userName>userName</userName>
</user_id>
用户名
xslt
..........................
如果我将
更改为
,则它不起作用。原因可能是什么。这里的pin是根元素
提前谢谢
如果我将
更改为,则它不起作用
如果您更改了,您还需要更改:
<xsl:apply-templates select="securityProfile/userName"/>
致:
否则,您将对不存在的节点应用模板。这里的根元素是pin?那么为什么我需要在这里再次提供pin?您不会再次提供它。模板的匹配模式将
/
根节点建立为当前上下文。从这个上下文来看,userName
的相对路径是pin/securityProfile/userName
。我认为,,,两者都是相同的。我是对的还是错的?你错了<代码>与根节点匹配<代码>与根元素匹配。根元素是根节点的子元素。-注意,不同的标准可能使用不同的术语来描述这两个节点;看:谢谢,我现在知道了。对于根节点(通常为文档节点,但可能不存在),以及它与选择根元素(通常为一个)的/somename
的不同之处,许多人通俗地认为根元素是一个,但它们并不相同,差异很小,但很重要。
<xsl:apply-templates select="securityProfile/userName"/>
<xsl:apply-templates select="pin/securityProfile/userName"/>