代码之家  ›  专栏  ›  技术社区  ›  user944513

如何在xslt中使用值标记名称?

  •  -3
  • user944513  · 技术社区  · 9 年前

    我正在做一个简单的演示,我正在解析xml。 我想展示 element name and its value ? 你能告诉我怎么展示吗 element node and its value 这是我的密码

    http://xsltransform.net/ncntCSr/1

    预计产量

    name : test
    p2 :pppp
    
    name : test2
    p2 :eeee
    
    name : testeee2
    p2 cccc
    

    我的代码

    <xsl:template match="firstname" >
            <xsl:for-each select="firstname">
                <h1><xsl:value-of select="name(.)"/></h1>
            </xsl:for-each>
        </xsl:template>
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   ScanQR    9 年前

    你需要对每一个循环 student 并选择 firstname 以获得所需的输出。

    http://xsltransform.net/ncntCSr/3

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:template match="/">
            <html>
                <body>
                    <xsl:apply-templates select="class" />
                </body>
            </html>
        </xsl:template>
        <xsl:template match="class" >
            <xsl:for-each select="student">
               <xsl:apply-templates select="firstname"/>
            </xsl:for-each>
        </xsl:template>
        <xsl:template match="firstname" >
          <h1>
            name : <xsl:value-of select="name"/> 
            <xsl:text> </xsl:text>
            p2 : <xsl:value-of select="p2"/>
        </h1>
        </xsl:template>
    
    </xsl:stylesheet>