问题描述:

I have XML which contains multiple customItems:

<?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>

I'm using this XSLT to transform it:

<?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>

But I'm only getting the first value "ArtworkDescription" in the result:

<field-list>

<field>

TestB2Bconvert4

</field>

</field-list>

If I remove some of the elements from the input file:

<?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>

I get what I'm looking for:

<field-list>

<field>

TestB2Bconvert4

</field>

<field>

TestB2Bconvert3

</field>

</field-list>

I cant figure out why, can anyone help me?

网友答案:

I'm answering this question myself so it can help others from the scrolling-list level.

Thanks to Martin Honnen, who spotted that I had question marks in the element tags of my input XML. These are not allowed in XML and will cause an XSLT to fail.

相关阅读:
Top