Xml Xls子字符串字符串长度以开头

Xml Xls子字符串字符串长度以开头,xml,xslt,Xml,Xslt,我对xsl非常陌生,只需要在项目中完成这一部分。因此,与其做大量的测试并失败,我想有人可以很容易地解决这个问题。我知道用其他语言编程,所以我想这对一些人来说是一个简单的例子 这就是问题所在。 我的模板如下所示: <xsl:template name ="TemplateName1"> <xsl:param name ="ParmId1"/> <cbc:Element1> <xsl:choose> <xsl:when test="$ParmId

我对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


感谢您的帮助。

假设您的输入为:

<?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>

如果参数与表达式^N?[1234567890]+$匹配,则可以使用XPath函数:

translate($ParmId1,'N','')
这个简单的方法从字符串中删除任何可能出现的N字符。较新版本的XPath/XSLT提供了更复杂的解决方案