【发布时间】:2014-06-19 17:08:18
【问题描述】:
XML 文件:
<generic-cv:generic-cv xmlns:generic-cv="http://www.cihr-irsc.gc.ca/generic-cv/1.0.0" lang="en" dateTimeGenerated="2014-05-30 11:40:50">
<section id="f589cbc028c64fdaa783da01647e5e3c" label="Personal Information">
<section id="2687e70e5d45487c93a8a02626543f64" label="Identification" recordId="4f7c2ebd789f407b939e05664f6aa7c0">
<field id="ee8beaea41f049d8bcfadfbfa89ac09e" label="Title">
<lov id="00000000000000000000000000000318">Mr.</lov>
</field>
<field id="98ad36fee26a4d6b8953ea764f4fed04" label="First Name">
<value type="String">Hara</value>
</field>
</section>
<section id="2687e70e5d45487c93a8a02626543f64" label="Identification" recordId="4f7c2ebd789f407b939e05664f6aa7c0">
<field id="ee8beaea41f049d8bcfadfbfa89ac09e" label="Title">
<lov id="00000000000000000000000000000318">Mr.</lov>
</field>
<field id="98ad36fee26a4d6b8953ea764f4fed04" label="First Name">
<value type="String">ali</value>
</field>
</section>
</section>
还有一个像这样的 xslt 文件
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:variable name="FirstName" select=".//field[@id='98ad36fee26a4d6b8953ea764f4fed04']/value"/>
<xsl:template match="/">
<html>
<head>
<title>Xml Convertor</title>
</head>
<body>
<h2><b> Personal Information</b></h2>
<ul>
<xsl:for-each select=".//section[@id='2687e70e5d45487c93a8a02626543f64']" >
<li>Name: $FirstName></li>
</xsl:for-each>
</ul>
</body>
</html>
而不是使用特定的代码值来获取 xml 文件中的正确信息。 我想使用(全局)变量,以便我可以轻松更改值。 例如,当我想查找并显示(在 html 中)名字时,我会查找代码“98ad36fee26a4d6b8953ea764f4fed04”。相反,我想设置一个变量,例如将 firstName 设置为此值并在 xml 文件中查找变量值。但是,当我将 first name 设置为变量并将其放在 for each 循环下时,它只会打印出名称 Hara 和不是阿里。有没有一种方法可以解决这个问题,而无需将变量声明放在 for each 循环中
【问题讨论】: