请问每个人每次只重复一次文本吗?

例如,我有这样的XML代码:
<quotes>
  <quote>
    <character>
      <name>LA FEU</name>
    </character>
  </quote>

  <quote>
    <character>
      <name>LA FEU</name>
    </character>
  </quote>

   <quote>
    <character>
      <name>LA FEU</name>
    </character>
  </quote>
</quotes>
我的XSLT代码将其转换为HTML:
<html>
      <body>
        <pre>
            <xsl:for-each select="quotes/quote">
            <!--Output name of the character in underline-->
            Name of character: <xsl:apply-templates select="//name"/> 
          </xsl:for-each>

        </pre>
      </body>
 </html>
输出如下:字符名称:LAFEULAFEULAFEU 你是想让NAME每次只重复一次吗?你能帮帮我吗?谢谢 示例角色名称:LAFEU             人物名称:LAFEU             人物名称:LAFEU ================================================== =============================================== 我想再问一个与这个问题有关的事情。 如果CHARACTER在QUOTES下多层,如下:
 <quotes>
      <quote>
        <!--play 1-->
        <play>
          <playtitle>All's Well That Ends Well</playtitle>
          <act>
            <acttitle>ACT IV</acttitle>
            <scene>
              <scenetitle>SCENE I</scenetitle>
              <speech>
                <name>
                  <name>LAFEU</name>
                </name>
................
如果在For-each声明中引用NAME,我试试这个,但不行
    <xsl:for-each select="quotes/quote">
            <!--Output name of the character in underline-->
            Name of character: <xsl:value-of select="play/*/name"/> 
   </xsl:for-each>
你能帮我解决这个问题吗?谢谢     
已邀请:
在您的XSLT代码中尝试这个:
<xsl:for-each select="quotes/quote/character">
    <!--Output name of the character in underline-->
    Name of character: <xsl:apply-templates select="name"/> 
</xsl:for-each>
    
更新:这个解决方案是为了避免有序集上的双打,我重读你的问题,并看到我可能会误解。我在这里留下我的答案,因为它至少告诉你如何摆脱不必要的每个结构。 你问的问题是,我担心初学者的水平。你应该首先学习基础知识。现在你问:“请为我做我的工作”。 如果我建议,请先在这里chekc:http://www.w3schools.com/xml/xml_xsl.asp 像这样 : 注意:(几乎)从不使用 - 每个!!!!当然不是在这里! 看这里 但是,如果你坚持使用它,你可以使用相同的前兄弟逻辑,如果你想在for-each关闭。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
    <body>
      <pre>    
        <xsl:apply-templates select="//quote[not(./character/name = preceding-sibling::quote/character/name)]/character/name" />    
      </pre>
    </body>
  </html> 
</xsl:template>

 <xsl:template match="name">
    <pre>
    <xsl:value-of select="."/>
    </pre>
  </xsl:template>
    
干得好!我试图尽可能少地对您的XSLT进行更改以实现所需的输出。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>
  <xsl:template match="/">
    <html>
      <body>
        <pre>
          <xsl:for-each select="quotes/quote">
            <!--Output name of the character in underline-->
            Name of character: <xsl:apply-templates select="character/name"/> 
          </xsl:for-each>
        </pre>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
这有以下输出:
<html>
  <body>
    <pre>
        Name of character: LA FEU
        Name of character: LA FEU
        Name of character: LA FEU
    </pre>
  </body>
</html>
    
我刚刚找到了处理这个问题的好方法:使用应用模板,非常感谢你们:)。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!--Handle the document: set up HTML page-->
  <xsl:template match="/">
    <html>
      <body>
        <pre>
          THIS IS ANOTHER TEST
          <!--Display number of quotes in the document-->
          There is <xsl:value-of select="count(/*/quote)"/> quotes in the document       
          <xsl:apply-templates/>
        </pre>
      </body>
    </html>
  </xsl:template>
  <!--Create the title for the play-->
  <xsl:template match="playtitle">
    Play title: <xsl:value-of select="."/>
  </xsl:template>
  <!--Create the title for the scene-->
  <xsl:template match="scenetitle">
    Scene title: <xsl:value-of select="."/>
  </xsl:template>
  <!--create the title for act-->
  <xsl:template match="acttitle">
   Act title: <xsl:value-of select="."/>
  </xsl:template>
  <!--create the name for the character-->
  <xsl:template match="name">
     Character name: <span style="font-weight:bold;text-decoration:underline;"> 
     <xsl:value-of select="."/>   
    </span>
  </xsl:template>
  <!--create the text for the quote-->
  <xsl:template match="line">
         Quote text:
            <xsl:value-of select="."/>
  </xsl:template>
</xsl:stylesheet>
    

要回复问题请先登录注册