【发布时间】:2020-04-16 14:39:20
【问题描述】:
我正在尝试在我的 xsl 代码中调用“firstName”节点,但是当我尝试调用“value-of select="firstName”时,它似乎不起作用,并且一旦转换,它不会显示任何内容为它。
我的 xsl 代码是:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="customers" select="document('customer.xml')/customers"/>
<xsl:template match="/">
<xsl:copy>
<xsl:for-each select="transactions/transaction">
<xsl:sort select="giftShop"/>
<xsl:sort select="transaction_date"/>
Shop: <xsl:value-of select="giftShop"/>
Date: <xsl:value-of select="transaction_date"/>
<xsl:for-each select="$customers">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
transactions.xml(第一个 xml 文件):
<?xml version="1.0"?>
<transactions>
<transaction>
<transaction_date>01/11/2019</transaction_date>
<customerID>8BLOJZWL</customerID>
<giftShop>1</giftShop>
<transactionID>BjYAtd7lmEOlQUVy</transactionID>
<value currency="gbp">149.99</value>
</transaction>
<transaction>
<transaction_date>01/11/2019</transaction_date>
<customerID>DR18OCFI</customerID>
<giftShop>2</giftShop>
<transactionID>aQ27lMvfnlzY4mkx</transactionID>
<value currency="gbp">100.11</value>
</transaction>
<transaction>
customer.xml(第二个 xml 文件):
<?xml version="1.0"?>
<customers>
<customer>
<prefix>Mrs</prefix>
<lastName>Samantha</lastName>
<givenName>Smith</givenName>
<addressID>213456</addressID>
<customerID>ASJ4OTLG</customerID>
</customer>
<customer>
<prefix>Mr </prefix>
<lastName>Cameron</lastName>
<givenName>Wills</givenName>
<addressID>125907</addressID>
<customerID>SID8RY23</customerID>
</customer>
</customers>
预期输出: 如果我的预期输出不是很准确也很抱歉,我对 xml 和 xsl 很陌生
<giftShop>
<transaction_date>
<transacation>
<customer>
我正在尝试调用特定的“客户数据”,但目前它会显示所有数据并在我尝试关闭文件时不断使我的 Notepad++ 崩溃。
非常感谢任何帮助!
【问题讨论】:
-
发布您正在处理的 XML 输入将极大地帮助我们理解和重现您的问题。
-
我可以包含它们,但是 xml 文件很大并且加载了数据
-
输入的一部分就足够了。尝试制作stackoverflow.com/help/minimal-reproducible-example。
-
我已经放入了我的两个 xml 文件,这些文件都大大缩短了,希望能有所帮助!
-
请同时添加预期的输出。
标签: xml xslt transform document