开发者

In the below xml code, i need to get "b1" and "b2" as my output using xslt

In the below xml code, I need to get "b1" and "b2" as my output using xsl开发者_运维问答t.

<xml>
    <a>
        <b>
            <b1>b1value</b1>
            <b2>b2value</b2>
        </b>
        <b>
            <b1>b1value2</b1>
            <b2> 2value2</b2>
        </b>
    </a>
</xml>

I wrote the following XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            <body>
                <xsl:for-each select="xml/a/b/*[b1='b1value']">
                    <xsl:value-of select="local-name()"/>
                    <br> </br>
                </xsl:for-each>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

But it doesn't give me any output.. why?

Instead if i write

<xsl:for-each select="xml/a/b/*">
 <xsl:value-of select="local-name()"/> 

the output is:

b1
b2
b1
b2

the output i need is:

b1 
b2


It's not clear exactly what you're trying to get for output.

However the reason you're not getting any output from your XSLT is that in your for-each, your xpath is looking for any children of <b> that also have a child <b> that contains "b1value".

You need to move your predicate:

  <xsl:template match="/">
    <html>
      <body>
        <xsl:for-each select="xml/a/b[b1='b1value']/*">
          <xsl:value-of select="local-name()"/>
          <br> </br>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>


Do you mean this:

<xsl:for-each select="xml/a/b/*[text()='b1value']">
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜