如何让文本每一次只重复一次? [英] HOw to make the text repeat only once every for-each?

查看:41
本文介绍了如何让文本每一次只重复一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我有这样的 XML 代码:

<引用><字符><name>LA FEU</name></字符></quote><引用><字符><name>LA FEU</name></字符></quote><引用><字符><name>LA FEU</name></字符></quote></quotes>

用于将其转换为 HTML 的 XSLT 代码:

<身体><预><xsl:for-each select="quotes/quote"><!--输出下划线字符的名称-->角色名称:<xsl:apply-templates select="//name"/></xsl:for-each>

</html>

输出是这样的:角色名称:LAFEULAFEULAFEU

如何让 NAME 每次只重复一次?你能帮我吗?谢谢你例如角色名称:LAFEU角色名称:LAFEU

角色名称:LAFEU

==================================================================================================

我想再问一件事与这个问题有关.如果 CHARACTER 位于 QUOTES 多层下,则如下所示:

 <引用><!--播放 1--><玩><playtitle>一切都很好,结局很好</playtitle><行动><acttitle>ACT IV</acttitle><场景><scenetitle>场景一</scenetitle><演讲><名称><name>LAFEU</name></名称>……………………………………………………………………………………………………………………………………

如何在 For-each 语句中引用 NAME,我尝试了这个,但不起作用

 <!--输出下划线字符的名称-->角色名称:<xsl:value-of select="play/*/name"/></xsl:for-each>

你能帮我解决这个问题吗?谢谢

解决方案

在您的 XSLT 代码中试试这个:

<!--输出下划线字符的名称-->角色名称:<xsl:apply-templates select="name"/></xsl:for-each>

for example I have the XML code like this:

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

My XSLT code to transform this to 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>

Output is like this: Name of character: LAFEULAFEULAFEU

HOw to make the NAME repeat only once every for-each? Would you please help me? THank you FOr example Name of character: LAFEU Name of character: LAFEU

Name of character: LAFEU

=================================================================================================

I would like to ask 1 more thing related to this question. IN case if CHARACTER is under QUOTES many layer, like this:

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

HOw to refer to NAME in the For-each statement , I try this, but not work

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

Would you please help me with this? THank you

解决方案

Try this in your XSLT code:

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

这篇关于如何让文本每一次只重复一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆