2015-10-08 102 views
0

是否有可能用XPath表達式替換標記屬性的值。 即:是否允許在屬性值中使用XPath函數

<?xml version="1.0" encoding="UTF-8"?> 

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:import href="../Product/templates.xsl"/> 
    <xsl:output method="xml"/> 

    <xsl:template name="root" match="/"> 
     <test-report start="substring(abcd, 1, 2)" stop="2015-10-07 16:54.103"> 
      <xsl:call-template name="temp"/> 
     </test-report> 
    </xsl:template> 


    <xsl:template name="temp"> 
     <xsl:value-of select="'TEXT_RIKO'"/> 
    </xsl:template> 

輸出是

<?xml version="1.0" encoding="UTF-8"?> 
<test-report start="substring(abcd, 1, 2)" stop="2015-10-07 16:54.103"> 
    TEXT_RIKO 
</test-report> 

我要的是(在輸出文件)開始屬性的值是功能ab的輸出。

謝謝!

回答

3

答案是「是」,但您需要使用Attribute Value Templates來執行此操作。

只需撰寫本

<test-report start="{substring(abcd, 1, 2)}" stop="2015-10-07 16:54.103"> 

大括號指示的表達式字面上被評價而不是輸出。

相關問題