[英]Xls substring string-length starts-with
我對xsl還是很陌生,只需要完成一個項目即可。 因此,我認為有人可以解決這個問題,而不是進行大量測試和失敗。 我知道用其他語言編程,所以我想這對某些人來說是簡單的例子?
這就是問題所在。 我有看起來像這樣的模板:
<xsl:template name ="TemplateName1">
<xsl:param name ="ParmId1"/>
<cbc:Element1>
<xsl:choose>
<xsl:when test="$ParmId1= 'N15'">Net per 15 days</xsl:when>
<xsl:when test="$ParmId1= '15'">Net per 15 days</xsl:when>
</xsl:choose>
</cbc:Element1>
</xsl:template>
我想要的是更動態的方法。 我知道參數將以字母開頭,然后是數字,或者只是數字。 只能是1-2位數字。 我希望結果像是:“每個“參數”天的凈收入”
如果僅參數不是以字母開頭,那么我需要更改$ ParmId1以刪除第一個字符。
*更新:第一個字母將始終為字母“ N”-例如:4,N4、30,N30。
感謝您的所有幫助。
如果您的參數與表達式^N?[1234567890]+$
匹配,則可以使用translate
XPath函數:
translate($ParmId1,'N','')
此簡單操作從字符串中刪除了所有可能的N
字符外觀。 較新版本的XPath / XSLT中提供了更復雜的解決方案
假設您的輸入為:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Result>N30</Result>
</root>
實現您指定的XSLT 1.0解決方案可以是:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" />
<xsl:template match="/root">
<xsl:call-template name="TemplateName1">
<xsl:with-param name="ParmId1" select="Result"/>
</xsl:call-template>
</xsl:template>
<xsl:template name ="TemplateName1">
<xsl:param name ="ParmId1"/>
<cbc:Element1>
<xsl:choose>
<xsl:when test="starts-with($ParmId1, 'N')">Net per <xsl:value-of select="substring-after($ParmId1,'N')" /> days</xsl:when>
<xsl:otherwise>Net per <xsl:value-of select="$ParmId1" /> days</xsl:otherwise>
</xsl:choose>
</cbc:Element1>
</xsl:template>
</xsl:stylesheet>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.