2015-06-05 124 views
1

如何使用xslt將xml中的文本轉換爲html中的超鏈接。如何將xml中的文本轉換爲html中的超鏈接使用xslt

我的XML代碼

<Steps>   
 
    <Filepath>C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png</Filepath> 
 
</Steps>

將其轉換成HTML我的XSLT代碼看起來像

<td width='15%'> 
 
    <xsl:element name="a"> 
 
\t <xsl:attribute name="href"> 
 
\t <xsl:value-of select="./Filepath"/> 
 
\t </xsl:attribute> 
 
\t <xsl:value-of select="./Filepath"/> 
 
    </xsl:element> \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
</td>

現在這代碼在html中寫入文件的整個路徑,但是我想只在文件的位置使用超鏈接在html中寫入「File」。下面

C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png
<td width="15%"><a href="C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png">C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png</a></td>

我的電流所產生的HTML代碼中給出我想要的是

<td width="15%"><a href="C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png">File</a></td>

誰能幫我我需要在xslt中做什麼更改。

回答

1

你告訴它的值爲:

<xsl:element name="a"> 
    <xsl:attribute name="href"> 
     <xsl:value-of select="./Filepath"/> 
    </xsl:attribute> 
    <xsl:value-of select="./Filepath"/> <!--This is the link text --> 
    </xsl:element>               

所以將其更改爲:

<xsl:element name="a"> 
    <xsl:attribute name="href"> 
     <xsl:value-of select="./Filepath"/> 
    </xsl:attribute> 
    File 
    </xsl:element> 
+0

這也會在'文件'這個單詞周圍的空白處添加。無論如何,HTML往往會崩潰,如果它自己在'​​'上,它不會有什麼區別,但是在某些情況下,這會以不需要的間隔結束。 – Flynn1179

1

或簡稱:

<a href="{Filepath}">File</a>