我已经查看了有关嵌套选择的其他一些帖子,但不相信它们解决了我的用例。本质上,我正在尝试通过 Web 服务在另一个系统中创建一个用户帐户,并且需要传递一个登录 ID,该登录 ID 源自我的 xml 中的一个字段,该字段基本上可以是任何东西,例如员工 ID、电子邮件地址、UUID 等。要使用的字段将来自生成 xml 的配置值。为简单起见,我将我的 xml 和 xslt 缩写,所以请不要建议我使用选择或 if 语句,因为我需要保持可能的 xml 字段从广泛开放中进行选择。
示例 XML:
<root>
<General>
<Name Prefix="MR" First="Mickey" Middle="M" Last="Mouse" Suffix="I" Title="BA" Gender="M" BirthMonth="02" BirthDay="26" BirthYear="1984"/>
<Email Work="test9999@acme.com" Home="Homeemail@gmail.com"/>
<EmployeeId>9948228</EmployeeId>
</General>
<ConfigProperties>
<LoginID>root/General/EmployeeId</LoginID>
</ConfigProperties>
</root>
XSL 示例:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no" encoding="utf-8" indent="yes" />
<xsl:template match="/">
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:variable name="xxLI" select="root/ConfigProperties/LoginID" />
<xsl:attribute name="LoginId"><xsl:value-of select="$xxLI"/></xsl:attribute>
</Response>
</xsl:template>
</xsl:stylesheet>
转换后的 XML:
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
LoginId="root/General/EmployeeId"/>
我真正希望回来的是:
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
LoginId="9948228"/>
我难住了。有什么想法吗?