tags:

views:

52

answers:

3

I have a XML like this

<root>
 <name>Smith</name>
 <info>
  <name>image</name>
  <value>smith.jpg</value>
 </info>
 <info>
  <name>birth</name>
  <value>2000-10-10</value>
 </info>
 <info>
  <name>moreinfo</name>
  <value>something1</value>
 </info>
 <info>
  <name>moreinfo2</name>
  <value>something2</value>
 </info>
</root>

how XSLT to check if info/name/text() = image, then it will display info/name/value()?

<div>
<xsl:value-of select="root/name" />
birth: xxxx 
</div>
+1  A: 

Well, you maybe mean something like info[name='image']/value, but I'm not really sure...

lexicore
A: 

?

<xsl:template match="/">
    <xsl:for-each select="root/info">
        <xsl:if test="name = 'image'">
        <xsl:value-of select="value"/>
        </xsl:if>
    </xsl:for-each>
</xsl:template>
Mark McLaren
+3  A: 

You seem to be rendering HTML, so my example renders the image value as an img element. This uses an attribute value template which is an expression in an attribute.

<div>
    <xsl:value-of select="root/name" />
    birth: <xsl:value-of select="root/info[name='birth']/value" />
    <img src="{root/info[name='image']/value}"/>
</div>
Lachlan Roche