簡體   English   中英

如何在xslt中包含一個子元素的所有子元素?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM