Richie
Richie

Reputation: 5199

XSLT Multiple CDATA sections

I am a bit of a novice in XLST but I'm having an issue which has me tearing my hair out. I have an XML lookup file that looks like this....

<car make='honda'>
    <model>
        <![CDATA[I am a civic]]>
    </model>
    <model>
        <![CDATA[I am a CRV]]>
    </model>
</car>

Using an XSLT stylesheet I am passing my primary file then going to this lookup file and trying to display what is in the CDATA section.....

<xsl:for-each select="document('lookup.xml')/car[@make='honda']">
    <p><xsl:value-of select="." /></p>
</xsl:for-each>

The problem I have is that the text in CDATA is being returned all together. For example this code currently produces...

<p>
I am a civic
I am a CRV
</p>

But I really want...

<p>I am a civic</p>
<p>I am a CRV</p>

Can anyone please help me with this one.

Thanks

Richard

Upvotes: 0

Views: 409

Answers (1)

Tim C
Tim C

Reputation: 70618

Instead of doing this....

<xsl:for-each select="document('lookup.xml')/car[@make='honda']"> 

Do this instead....

<xsl:for-each select="document('lookup.xml')/car[@make='honda']/model"> 

This will iterate over the model elements individually, which is what you require.

Upvotes: 3

Related Questions