我有一个xslt,可将xml转换为CSV。但是我不希望输出中的记录超过100个字符。以下是我的xslt,有人可以帮我将每条输出记录限制为100个字符吗?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wd="urn:com.workday.report/Positive_Pay_SVB"
xmlns:this="urn:this-stylesheet" exclude-result-prefixes="xs" version="2.0">
<xsl:output method="text"/>
<xsl:variable name="delimiter" select="' '"/>
<xsl:variable name="linefeed" select="'
'"/>
<xsl:template match="wd:Report_Data">
<xsl:apply-templates select="wd:Report_Entry/wd:Payments_group"/>
<xsl:template match="wd:Report_Entry/wd:Payments_group">
<xsl:variable name="Paymentamount" select="translate(normalize-space(translate(wd:Payment_Total_Amount,'.','')),'','')"/>
<xsl:value-of select="wd:CF_Account_number_HSBC_Canada"/>
<xsl:value-of select="$delimiter"/>
<xsl:value-of select="concat(substring('0000000000', 1 + string-length(wd:Check_Number)), wd:Check_Number)"/>
<xsl:value-of select="concat(substring('0000000000', 1 + string-length($Paymentamount)), $Paymentamount)"/>
<xsl:value-of select="wd:Payment_Date"/>
<xsl:value-of select="$delimiter"/>
<xsl:value-of select="wd:Payment_Payee/@wd:Descriptor"/>
<xsl:value-of select='$linefeed'/>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:2)
您始终可以使用
限制值的输出长度。substring(value,1,100)
如果您要限制多个xsl:value-of
,请串联它们,然后应用上面的表达式:
substring(concat(value1,value2,...),1,100)
因此,将其应用于您的模板后,可能会像这样:
<xsl:template match="wd:Report_Entry/wd:Payments_group">
<xsl:variable name="Paymentamount" select="translate(normalize-space(translate(wd:Payment_Total_Amount,'.','')),'','')"/>
<xsl:value-of select="substring(wd:CF_Account_number_HSBC_Canada,1,100)"/>
<xsl:value-of select="$delimiter"/>
<xsl:value-of select="substring(concat(substring('0000000000', 1 + string-length(wd:Check_Number)), wd:Check_Number, concat(substring('0000000000', 1 + string-length($Paymentamount)), $Paymentamount), wd:Payment_Date),1,100)"/>
<xsl:value-of select="$delimiter"/>
<xsl:value-of select="substring(wd:Payment_Payee/@wd:Descriptor,1,100)"/>
<xsl:value-of select='$linefeed'/>
</xsl:template>