繁体   English   中英

如何在与 xslt1.0 连接之前修改元素的文本

[英]how can modify the text of a element before concatenating it with xslt1.0

我试图在一个元素中连接所有具有相同名称的标签(我的 XSLT 已经这样做了),问题是文本开头有一个连字符,结尾有一个空格,我必须删除,我可以不做这最后一部分。 我有这个输入:

<LIST>
   <PLACE>
       <level>-this </level>
       <level>-Is </level>
       <level>What</level>
       <level>-I</level>
       <level>Want </level>
   </PLACE>
</LIST>

并且需要一个 output 像:

<LIST>
   <PLACE>
       <level>thisIsWhatIWant</level>
   </PLACE>
</LIST>

我正在使用这个 XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
    <xsl:template match="PLACE">
      <PLACE>
            <level>
<!-- I tried this to eliminate the hyphen -->
             <xsl:value-of select="translate(.,'-','')"/>
<!-- and this to eliminate the white space at the end of the elements -->
              <xsl:value-of select="translate(.,' ','')"/>
            <xsl:value-of select="normalize-space(concat(level[1],level[2],level[3],level[4],level[5]))" />
            </level>
      </PLACE>
    </xsl:template>
</xsl:stylesheet>

如何修改我的 xslt 以在连接之前消除文本中的空格和连字符。

谢谢

用这个:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements="*"/>
  
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="PLACE">
    <PLACE>
      <level>
          <xsl:apply-templates/>
      </level>
    </PLACE>
  </xsl:template>
  
  <xsl:template match="level">
    <xsl:value-of select="normalize-space(translate(.,'-',''))"/>
  </xsl:template>
</xsl:stylesheet>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM