Advanced XML rule example: Format an extracted XML value with XSL
This topic contains two examples that show how to reformat values extracted from XML invoices.
Example 1: Changing the year format YYYY to YY
This example is for the InvoicePeriodStart field in a Svefaktura invoice:
- Select the
InvoicePeriodStart field in the Fields section on the
Fields
tab of the XML Mapper (on the right side of the window).
- Click the button to the right of the value:
if no rule has been defined, or
if there is already an existing rule for the field.
- Click the button to the right of the value:
- Select Use XSL on the bottom left of the screen.
- Click
Import from advanced rules. This example
assumes that no advanced rules have been defined for this field. Some initial
XSL code relevant to the selected field is added to the XSL edit box.
<xsl:template match="/"> <xsl:for-each select="//x:Invoice/x:InvoicingPeriod/cbc:StartDateTime"> </xsl:for-each> </xsl:template>
- Change the code like this to change the format from YYYY to YY.
Required changes added with bold text:
<xsl:template match="/">
<xsl:for-each select="//x:Invoice/x:InvoicingPeriod/cbc:StartDateTime">
<xsl:choose>
<xsl:when test="starts-with(.,'20')">
<xsl:value-of select="substring(.,3)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring(.,1)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
Click Extract and review the image to check the results. If you need to modify the rule, you need to click it in the Rules applied to map this field box, click Del to delete it, make the changes needed to fix the rule, and click Add again to add the modified rule. If you need to modify a condition, the process is the same (and if a rule is based on it, the rule is also deleted if you delete the condition).
Consider if the change(s) should apply to all documents or only those for the current XML invoice definition. Click Save XML definition to save the change for the current XML invoice definition only (that is, the current sender). Click Save XML profile if you want the rule to apply to all XML invoices that match the XML invoice profile regardless of the XML invoice definition.
Example 2: Removing additional characters
This example removes unnecessary characters from the extracted value for the SupplierTaxNumber1 field (that is, a number like SE556078650001 is changed to 5560786500).
- Select the SupplierTaxNumber1 field in the Fields section on the Fields tab of the XML Mapper (on the right side of the window).
- Click the
button to the right of the value to display the Field mapping rules for the field on the left.
- Select Use XSL on the bottom left of the screen.
- Click the
Import from advanced rules to add the XSL
equivalent of the advanced rules above to the XSL editing box below, or to add
some initial XSL code to start with if no advanced rule has been defined. (See
what it looks like if no advanced rule is defined.)
<xsl:template match="/"> <xsl:for-each select="//x:Invoice/x:InvoicingPeriod/cbc:StartDateTime"> </xsl:for-each> </xsl:template>
- Change the code like this to change the format from YYYY to YY.
Required changes added with bold text:
<xsl:template match="/">
<xsl:for-each select="/x:Invoice/cac:SellerParty/cac:Party/cac:PartyTaxScheme">
<xsl:if test="cac:TaxScheme/cac:ID='VAT'">
<!-- <xsl:value-of select="CompanyID"/> -->
<xsl:choose>
<xsl:when test="starts-with(cac:CompanyID,'SE')">
<xsl:value-of select="substring(cac:CompanyID,3,10)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring(cac:CompanyID,1)"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if>
<xsl:if test="TaxScheme/ID!='VAT'"></xsl:if>
</xsl:for-each>
</xsl:template>
Click Extract and review the image to check the results. If you need to modify the rule, you need to click it in the Rules applied to map this field box, click Del to delete it, make the changes needed to fix the rule, and click Add again to add the modified rule. If you need to modify a condition, the process is the same (and if a rule is based on it, the rule is also deleted if you delete the condition).
Consider if the change(s) should apply to all documents or only those for the current XML invoice definition. Click Save XML definition to save the change for the current XML invoice definition only (that is, the current sender). Click Save XML profile if you want the rule to apply to all XML invoices that match the XML invoice profile regardless of the XML invoice definition.
Other examples of advanced XML rules:
Correct a misspelled field name in connection with master data
Modify an extracted XML field value with XSL
Remove hyphens (-) from an extracted value
Select node X based on node Y (or on attribute a)
Select a specific node when more than one node matches after using a standard rule
Select node X if it exists and node Y if it does not
Specify a constant value for a field
Summarize data from line items as a note in a summary invoice
Translate an XML value to one that Tungsten ReadSoft Entrance understands