[英]How to open all xml sub-elements belonging to a certain element in a pandas dataframe, with each sub-element in a row
[英]How to include all the sub-elements of a sub-element in xslt?
我有这样的 xml 代码:
<Car no="1" CarID="id_111-111">
<ProductionD>2001-07-12</ProductionD>
<MarketValue currency="$">1999.5</MarketValue>
<VisitedCountries>
<Country no="1">
Poland
</Country>
<Country no="2">
England
</Country>
</VisitedCountries>
<InspectionDates>
2011-09-13 2013-08-13
</InspectionDates>
</Car>
我想在表格中显示所有Car
内容。 我想出了这个 xsl 代码:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:output method="xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
<xsl:template match="/">
<html>
<head></head>
<body>
<table>
<xsl:for-each select="CarOwnerships/Cars/Car">
<tr>
<td><xsl:value-of select="ProductionD"/></td>
<td><xsl:value-of select="MarketValue"/></td>
<td><xsl:for-each select="VisitedCountries/Country">
<xsl:value-of select="Country"/>
</xsl:for-each></td>
<td><xsl:value-of select="InsuranceID"/></td>
<td><xsl:value-of select="Phone"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
但它只显示第一个Country
,而不是两者。 怎么可能做到这一点?
<xsl:for-each select="VisitedCountries/Country">
<xsl:value-of select="Country"/>
</xsl:for-each>
应该
<xsl:for-each select="VisitedCountries/Country">
<xsl:value-of select="."/>
</xsl:for-each>
但是使用 XSLT 2 只需<xsl:value-of select="VisitedCountries/Country"/>
就足够了,不需要for-each
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.