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