开发者

XSLT check in the same parent

I have a XML like this

<root>
 <name>Smith</name>
 <info>
  <name>image</name>
  <value>开发者_Python百科;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>


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>


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


?

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜