2011-03-02 157 views
0

我有下面的XMLXSLT CONCAT字符串

<R N="14" MIME="application/pdf"> 
     <RK>7</RK> 
     <FS NAME="date" VALUE="2007-11-01" /> 
     <MT N="Abstract" V="Lorem Ipsum is simply dummy text of the printing " /> 
     <MT N="Abstract1" V="and typesetting industry. Lorem Ipsum has been the industry's standard " /> 
     <MT N="Abstract2" V="dummy text ever since the 1500s, when an unknown printer took a galley" /> 
     <MT N="CreationDate" V="D:20070730173554+05'30'" /> 
     <MT N="Creator" V="PageMaker 6.5" /> 
     <MT N="Producer" V="Acrobat Distiller 8.0.0 (Windows)" /> 
     <MT N="ModDate" V="D:20071024091122+05'30'" /> 
     <S> 
      <b>...</b> handling/storage. Operational reactor physics plays an important role in<br/> 
      efficient, smooth and safe operation of <b>nuclear reactor</b>. In <b>...</b> 
     </S> 
     <LANG>en</LANG> 
    </R> 

使用XSLT,我需要連接摘要,Abstract1,Abstract2,Abstract3值......等等。

我的XSLT是這樣

<xsl:template match="R"> 
    <xsl:choose> 
     <xsl:when test="MT[@N = 'Abstract' and @V != '']"> 
      <xsl:call-template name="reformat_keyword"> 
       <xsl:with-param name="orig_string" select="concat(MT[@N='Abstract']/@V,MT[@N='Abstract1']/@V,MT[@N='Abstract2']/@V)" /> 
      </xsl:call-template> 
     </xsl:when> 
     <xsl:otherwise> 
      <xsl:if test="$show_res_snippet != '0'"> 
       <xsl:call-template name="reformat_keyword"> 
        <xsl:with-param name="orig_string" select="S" /> 
       </xsl:call-template> 
      </xsl:if> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 

取而代之的是靜態的級聯,我需要一個通用的功能。

+0

可能重複http://stackoverflow.com/questions/5168867/ XSLT改造,串連接) – 2011-03-02 16:05:50

回答

0

如果我得到你的權利,你可以這樣做

<xsl:variable name="con-cats"><xsl:apply-templates 
    select="MT[starts-with(@N,'Abstract')]" 
    mode="concatthem"/></xsl:variable> 

別處:

<xsl:template match="MT" mode="concatthem"> 
<xsl:value-of select="@V"/> 
</xsl:template> 
<xsl:template match="*|text()" mode="concatthem" /> 

(沒有測試過,可能有錯誤)。

+0

我估摸這個問題是如何選擇其中屬性具有非恆定值... – rene 2011-03-02 09:57:12

+0

thanks.Its關閉節點。它連接了MT下的所有字符串。我需要選擇性拼接只有抽象的,Abstract1,Abstract2 ..等。其最好的,如果這個可以進行通用的。這意味着,現在它是抽象的,後來可能是Creator1,Creator2等 – itsbalur 2011-03-02 10:00:05

+0

啊。那麼,你可以選擇'MT [開始,用(@ N「摘要」)]',選擇部分只是一個例子。 – 2011-03-02 10:12:37

4

在XSLT 2.0,這是

<xsl:variable name="answer" 
    select="string-join(MT[starts-with(@N, 'Abstract']/@V, '')"/> 

在XSLT 1.0,這是

<xsl:variable name="answer"> 
    <xsl:for-each select="MT[starts-with(@N, 'Abstract']"> 
    <xsl:value-of select="@V"/> 
    </xsl:for-each> 
</xsl:variable> 
[XSLT轉換,字符串連接(的