1
我需要找到一種方法來應對以下XML的空格和換行:在XSLT使用空格和換行處理1
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<Message.body>
<Text>This is
an attachment text
with whitespaces and linebreaks
File name: https://somerandomurl.com/123.txt
File Type: txt
</Text>
</Message.body>
而這裏的XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<root>
<xsl:choose>
<xsl:when test="(starts-with(Message.body/Text, 'This is an attachment link:'))" />
<xsl:otherwise>
xxx
</xsl:otherwise>
</xsl:choose>
<Name>
<xsl:value-of select="substring-before(substring-after(Message.body/Text, 'File Name: '), 'File Type: ')"/>
</Name>
<Type>
<xsl:value-of select="substring-after(Message.body/Text, 'File Type: ')"/>
</Type>
</root>
這部分:
<xsl:when test="(starts-with(Message.body/Text, 'This is an attachment link:'))" />
當然不會工作,因爲中間有空格的換行符。此外,下面的線不與期望的結果,由於提到的問題:
實際結果:
<Name>https://somerandomurl.com/123.txt
</Name>
<Type>txt
</Type>
期望的結果:
<Name>https://somerandomurl.com/123.txt</Name>
<Type>txt</Type>
我應該嘗試用空格替換所有換行符,或者XSLT 1有沒有更簡單的方法?
在此先感謝!
非常感謝! :) – CoffeeCups