2017-02-16 119 views
-1

我有XML其中包含多個customItems:XSLT的for-each返回第一個子元素只

<?xml version="1.0" ?> 
<root> 
    <customItem> 
     <CustomerName>1Test</CustomerName> 
     <PONumber>321</PONumber> 
     <CustomerProofRequired>true</CustomerProofRequired> 
     <JobType>PVC Banner</JobType> 
     <ArtworkDescription>TestB2Bconvert4</ArtworkDescription> 
     <TrimSizeWidthinmm>5000</TrimSizeWidthinmm> 
     <TrimSizeHeightinmm>6000</TrimSizeHeightinmm> 
     <ChooseMedia>Bsmart PVC 510g</ChooseMedia> 
     <BleedRequired?>true</BleedRequired?> 
     <Replacementartwork?>false</Replacementartwork?> 
     <MultiItemJob>Yes</MultiItemJob> 
     <Quantity>1</Quantity> 
     <SquareMetres>30</SquareMetres> 
     <Price>120</Price> 
    </customItem> 
    <customItem> 
     <CustomerName>1Test</CustomerName> 
     <PONumber>321</PONumber> 
     <CustomerProofRequired>true</CustomerProofRequired> 
     <JobType>Vinyl Print</JobType> 
     <ArtworkDescription>TestB2Bconvert3</ArtworkDescription> 
     <TrimSizeWidthinmm>500</TrimSizeWidthinmm> 
     <TrimSizeHeightinmm>500</TrimSizeHeightinmm> 
     <ChooseMedia>Promotional (Budget Short Term Vinyl)</ChooseMedia> 
     <BleedRequired?>true</BleedRequired?> 
     <Replacementartwork?>false</Replacementartwork?> 
     <MultiItemJob>Yes</MultiItemJob> 
     <Quantity>7</Quantity> 
     <SquareMetres>0.25</SquareMetres> 
     <Price>1.75</Price> 
    </customItem> 
</root> 

我使用這個XSLT轉換它:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" /> 

<xsl:template match="/"> 
<field-list> 


<xsl:for-each select="root/customItem"> 
<field> 
<xsl:value-of select="ArtworkDescription"/> 
</field> 
</xsl:for-each> 

</field-list> 
</xsl:template> 

但我只得到第一個值「ArtworkDescription」中的結果爲:

<field-list> 
    <field> 
     TestB2Bconvert4 
    </field> 
</field-list> 

如果我從輸入文件中刪除了一些元素:

<?xml version="1.0" ?> 
<root> 
    <customItem> 
     <CustomerName>1Test</CustomerName> 
     <PONumber>321</PONumber> 
     <CustomerProofRequired>true</CustomerProofRequired> 
     <JobType>PVC Banner</JobType> 
     <ArtworkDescription>TestB2Bconvert4</ArtworkDescription> 


    </customItem> 
    <customItem> 
     <CustomerName>1Test</CustomerName> 
     <PONumber>321</PONumber> 
     <CustomerProofRequired>true</CustomerProofRequired> 
     <JobType>Vinyl Print</JobType> 
     <ArtworkDescription>TestB2Bconvert3</ArtworkDescription> 
    </customItem> 
</root> 

我得到了我在尋找:

<field-list> 
    <field> 
     TestB2Bconvert4 
    </field> 
    <field> 
     TestB2Bconvert3 
    </field> 
</field-list> 

我無法弄清楚,爲什麼,誰能幫助我?

+1

我不認爲' true是XML允許的,所以我懷疑你得到的第一個樣本是根據XSLT提供的。 –

+0

斑點!它在我刪除問號時起作用。 – James

回答

0

我自己回答這個問題,所以它可以幫助其他人從滾動列表級別。

感謝Martin Honnen,他發現我在輸入XML的元素標記中有問號。這些在XML中是不允許的,並且會導致XSLT失敗。

相關問題