<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:transform xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0">
<!--another one-->
<xsl:template match="/">
<xsl:for-each select = "//person"><br/>
<xsl:if test="name = 'Rose'">
<xsl:value-of select="name"/>
</xsl:if>
<xsl:value-of select="sex"/>
</xsl:for-each>
  </xsl:template>
</xsl:transform>

解决方案 »

  1.   

    谢谢 kreven(天地无用恨离别):理解你写的了.能解释一下我那个的结果吗?
      

  2.   

    你说的是我写的结果吗?
    match="/"表示匹配全文
    for-each你知道的吧,是循环,循环遍历xml文件,Rose必须加条件才可以指定。
    在循环中的sex肯定一样输出,如果你想再换行可以再加<br/>
      

  3.   

    你写的template应该要取个名字,供下面调用,我用call-template吗?也是调用template
      

  4.   

    <xsl:template match="person[name='Rose']">
       <xsl:apply-templates select="name" />
       <xsl:apply-templates select="sex" />
      </xsl:template>分别为调用匹配name与sex的xpath模板,如果没有,看有没有满足这条件的节点list
    有就全部list出来,不含可见标签
       <xsl:apply-templates select="name" />
       <xsl:apply-templates select="sex" />你喜欢可改:<?xml version = "1.0" encoding = "UTF-8"?>
    <xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0">  
      <!--another one-->
      <xsl:template match="person[name='Rose']">
       <xsl:apply-templates select="name" />
       <xsl:apply-templates select="sex" />
      </xsl:template>
      <xsl:template match="name">
        name is :<xsl:value-of select="."/>
      </xsl:template>  <xsl:template match="sex">
        sex is :<xsl:value-of select="."/>
      </xsl:template>
     
    </xsl:stylesheet>
    //分该给我,我要分