Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何仅从每次字符长度可变的子字符串中获取最后4个字符_Xml_Xslt_Xslt 1.0 - Fatal编程技术网

Xml 如何仅从每次字符长度可变的子字符串中获取最后4个字符

Xml 如何仅从每次字符长度可变的子字符串中获取最后4个字符,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,我正在为xml优化发票,我只想要变量的最后4个字符。对于我收到的每个发票,变量可以有不同长度的字符,但我只希望最后4个字符 我已经用一个子字符串代码尝试过了,但是我需要给出一个具体的长度,代码需要从中获取最后4个字符 我使用的代码: <xsl:template match="/"> <xsl:for-each select="/x:Invoice"> <xsl:if test="."><xsl:value-of select="subs

我正在为xml优化发票,我只想要变量的最后4个字符。对于我收到的每个发票,变量可以有不同长度的字符,但我只希望最后4个字符

我已经用一个子字符串代码尝试过了,但是我需要给出一个具体的长度,代码需要从中获取最后4个字符

我使用的代码:

<xsl:template match="/">
   <xsl:for-each select="/x:Invoice">
      <xsl:if test="."><xsl:value-of select="substring(translate(cbc:Note,' ',''),27,4)"/></xsl:if>
   </xsl:for-each>
</xsl:template>

这是发票的代码:

<UBLVersionID>2.0</UBLVersionID>
<CustomizationID>1.0</CustomizationID>
<ProfileID>PowerOnline</ProfileID>
<ID>194545</ID>
<IssueDate>2019-05-16</IssueDate>
<InvoiceTypeCode>1</InvoiceTypeCode>
<Note>FB - bestelling voor HH7416</Note>
<TaxPointDate>2019-05-16</TaxPointDate>
<DocumentCurrencyCode>EUR</DocumentCurrencyCode>
<LineCountNumeric>7</LineCountNumeric>
<OrderReference>
<ID>Invoice of an supplier</ID>
<SalesOrderID>19538</SalesOrderID>
<IssueDate>2019-04-30</IssueDate>
2.0
1
电力在线
194545
2019-05-16
1.
FB-贝斯特林voor HH7416
2019-05-16
欧元
7.
供应商发票
19538
2019-04-30

预期结果是/x:Invoice/cbc:Note so 7416的最后4个字符。注释有时可能是FB-HH6464,因此我始终希望使用该cbc的最后4个字符:注释

您可以将
字符串长度
子字符串
结合使用来获取最后4个字符

<xsl:value-of select="substring(cbc:Note, string-length(cbc:Note) - 3)" />


(因此,执行
字符串长度(cbc:Note)
将获得最后一个字符,
字符串长度(cbc:Note)-1
将获得最后两个字符,依此类推……

谢谢!!这是为我做的:)祝您愉快,先生