tags:

views:

260

answers:

2

Hey All,

I've got some XML elements with a number attached as more are available.

Such as this:

<Images>
    <Image1>C:\Path\To\AnImage</Image1>

    <Image2>C:\Path\To\AnotherImage</Image2>
</Images>

The amount of Images in each XML doc is variable. How can I make sure that my XSL file will show all elements inside the tag?

I also want to put each of the strings inside each ImageX tag inside a Img src="stringfromxmlelement" with XSL? Is this possible?

Tony

+1  A: 

I'd try something along these lines:

<xsl:template match="Images">
  <xsl:for-each select="*">
    <img src="{text()}" />
  </xsl:for-each>
</xsl:template>
ndim
+6  A: 
<xsl:template match="Images/*[starts-with(name(),'Image']">
<img src="{.}" />
</xsl:template>

BTW, perhaps you can't change the XML tag names, but it would better to name the inner tags as Image rather than ImageX, which is probably unneccesary.

Doug D
Agreed about the tag names - if there is a need to distinguish between them or to sort then one should add an appropriate attribute
Murph
What's `</>`? I'm quite sure this is illegal.
Tomalak
It's just a quick (illegal) way to type a closing tag. The xsl:template tag would need to be properly closed.
Doug D
BTW, it's also a (legal) shortcut in SGML, which is the father of XML. Sometimes I wish XML had adopted the notation. :-)
Doug D
Legalised ... newbies might get confused
Rashmi Pandit