Skip to content

Commit

Permalink
Update create-syntax.xsl
Browse files Browse the repository at this point in the history
  • Loading branch information
RikardLarsson-BEAst authored Feb 28, 2024
1 parent bc09816 commit 1779cd8
Showing 1 changed file with 165 additions and 35 deletions.
200 changes: 165 additions & 35 deletions tools/create-syntax.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,55 @@
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:synstr="urn:fdc:difi.no:2017:vefa:structure-1"
xmlns="urn:fdc:difi.no:2017:vefa:structure-1"
exclude-result-prefixes="xsl fn synstr">
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xsl fn synstr xs">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:param name="varOverrideSample"/>
<xsl:variable name="varOverrideSampleXml" select="document($varOverrideSample)"/>
<xsl:variable name="varTermNs" select="/synstr:Structure/synstr:Namespace"/>
<xsl:variable name="varDocumentTerm" select="/synstr:Structure/synstr:Document/synstr:Term"/>
<xsl:variable name="varDocumentTermNsPrefix" select="substring-before($varDocumentTerm, ':')"/>
<xsl:variable name="varDocumentTermNs" select="translate($varTermNs[@prefix=$varDocumentTermNsPrefix],'&quot;','')"/>
<xsl:variable name="varDocumentTermQname" select="replace( $varDocumentTerm, concat($varDocumentTermNsPrefix, ':'), concat('Q{', $varDocumentTermNs, '}') )"/>
<xsl:template match="comment()|processing-instruction()|/">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="synstr:Element">
<!--xsl:variable name="varDocXPath">
<xsl:for-each select="ancestor-or-self::*">
<xsl:choose>
<xsl:when test="fn:name(.)='Structure'">
</xsl:when>
<xsl:otherwise>
<xsl:text>/</xsl:text>
<xsl:value-of select="synstr:Term"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable-->
<xsl:param name="paramIncludedFile"/>
<xsl:param name="paramXpathContext"/>
<!--xsl:if test="contains($paramXpathContext, 'StandardItemIdentification')">
<xsl:message>
<xsl:value-of select="$paramIncludedFile"/>: <xsl:value-of select="$paramXpathContext"/>
</xsl:message>
</xsl:if-->
<xsl:variable name="varDocXPath2">
<xsl:for-each select="ancestor-or-self::*">
<xsl:choose>
<xsl:choose>
<xsl:when test="$paramIncludedFile != ''">
<xsl:variable name="xpathTerm" select="synstr:Term"/>
<xsl:variable name="xpathTermNsPrefix" select="substring-before(synstr:Term, ':')"/>
<xsl:variable name="xpathTermNs" select="translate($varTermNs[@prefix=$xpathTermNsPrefix],'&quot;','')"/>
<xsl:value-of select="concat($paramXpathContext, '/', replace( $xpathTerm, concat($xpathTermNsPrefix, ':'), concat('Q{', $xpathTermNs, '}') ))"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="ancestor-or-self::*">
<xsl:choose>
<xsl:when test="fn:name(.)='Structure'">
</xsl:when>
<xsl:otherwise>
<xsl:text>/</xsl:text>
<xsl:variable name="xpathTerm" select="synstr:Term"/>
<xsl:variable name="xpathTermNsPrefix" select="substring-before(synstr:Term, ':')"/>
<!--Added translate function to solve bug with invoice raw XML from Peppol primary source file-->
<xsl:variable name="xpathTermNs" select="translate(/synstr:Structure/synstr:Namespace[@prefix=$xpathTermNsPrefix],'&quot;','')"/>
<xsl:variable name="xpathTermNs" select="translate($varTermNs[@prefix=$xpathTermNsPrefix],'&quot;','')"/>
<!--xsl:variable name="xpathTermNs" select="$varTermNs[@prefix=$xpathTermNsPrefix]"/-->
<xsl:value-of select="replace( $xpathTerm, concat($xpathTermNsPrefix, ':'), concat('Q{', $xpathTermNs, '}') )"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:choose>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="varOverrideNode">
<xsl:evaluate xpath="$varDocXPath2" context-item="$varOverrideSampleXml"/>
Expand All @@ -58,20 +70,27 @@
<xsl:variable name="varOverrideNode_ValueType" select="$varOverrideNode/child::*/processing-instruction('ValueType')"/>
<xsl:variable name="varOverrideNode_Value" select="$varOverrideNode/child::*/child::text()[1]"/>
<!--xsl:if test="$varDocXPath = '/ubl:Order/cac:AdditionalDocumentReference/cbc:ID' or $varDocXPath = '/ubl:Order/cac:AdditionalDocumentReference'">
<xsl:message>
<xsl:message>
XPath: <xsl:value-of select="$varDocXPath"/>
Value: <xsl:value-of select="$varOverrideNode_Value"/>
</xsl:message>
</xsl:if-->
</xsl:message>
</xsl:if-->
<!--xsl:if test="(contains($varDocXPath2, 'AccountingCustomerParty') and contains($varDocXPath2, 'EndpointID')) or (contains($varDocXPath2, 'CardAccount'))">
<xsl:message>
Param Included File: <xsl:value-of select="$paramIncludedFile"/>
Param Context XPath: <xsl:value-of select="$paramXpathContext"/>
XPath: <xsl:value-of select="$varDocXPath2"/>
Value: <xsl:value-of select="$varOverrideNode_Value"/>
</xsl:message>
</xsl:if-->
<xsl:choose>
<xsl:when test="$varOverrideNode_Description!='' and not(empty($varOverrideNode_Description))">
<Description>
<xsl:value-of select="normalize-space($varOverrideNode_Description)"/>
</Description>
</xsl:when>
<xsl:when test="$varOverrideNode_DescriptionAddFirst!='' and not(empty($varOverrideNode_DescriptionAddFirst))">
<Description>
BEAst: <xsl:value-of select="normalize-space($varOverrideNode_DescriptionAddFirst)"/>
<Description>BEAst: <xsl:value-of select="normalize-space($varOverrideNode_DescriptionAddFirst)"/>
<xsl:if test="synstr:Description != ''">
<xsl:value-of select="concat('&#xa;', ' Peppol: ', normalize-space(synstr:Description))"/>
</xsl:if>
Expand All @@ -87,7 +106,7 @@
</xsl:when>
<xsl:otherwise>
<Description>
<xsl:apply-templates select="normalize-space(synstr:Description)"/>
<xsl:apply-templates select="normalize-space(synstr:Description)"/>
</Description>
</xsl:otherwise>
</xsl:choose>
Expand Down Expand Up @@ -137,8 +156,7 @@
<xsl:copy-of select="synstr:Reference[@type='CODE_LIST']"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<!--xsl:when test="normalize-space($varOverrideNode_Value)!='' and not(empty(normalize-space($varOverrideNode_Value)))"-->
<!--xsl:choose>
<xsl:when test="normalize-space($varOverrideNode_Value)!=''">
<Value>
<xsl:choose>
Expand All @@ -161,20 +179,132 @@
<xsl:value-of select="normalize-space($varOverrideNode_Value)"/>
</Value>
</xsl:when>
<!--xsl:when test="not(empty(synstr:Value))">
<xsl:copy-of select="synstr:Value"/>
</xsl:when-->
<xsl:otherwise>
<xsl:copy-of select="synstr:Value"/>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="synstr:Attribute"/>
<xsl:apply-templates select="child::synstr:Include|child::synstr:Element"/>
</xsl:choose-->
<xsl:apply-templates select="synstr:Value">
<xsl:with-param name="paramOverrideNode" select="$varOverrideNode"/>
</xsl:apply-templates>
<xsl:apply-templates select="synstr:Attribute">
<xsl:with-param name="paramOverrideNode" select="$varOverrideNode"/>
</xsl:apply-templates>
<xsl:apply-templates select="child::synstr:Include|child::synstr:Element">
<xsl:with-param name="paramIncludedFile" select="$paramIncludedFile"/>
<xsl:with-param name="paramXpathContext" select="$varDocXPath2"/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="synstr:Include">
<xsl:variable name="varIncludeXml" select="document(.)"/>
<xsl:apply-templates select="$varIncludeXml/synstr:Element"/>
<xsl:param name="paramIncludedFile"/>
<xsl:param name="paramXpathContext"/>
<!--xsl:variable name="varIncludedFile" select="."/-->
<xsl:variable name="varIncludedFile">
<xsl:choose>
<xsl:when test="$paramIncludedFile != ''">
<xsl:value-of select="$paramIncludedFile"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="varIncludeXml" select="document(.)"/>
<xsl:apply-templates select="$varIncludeXml/synstr:Element">
<xsl:with-param name="paramIncludedFile" select="$varIncludedFile"/>
<xsl:with-param name="paramXpathContext" select="$paramXpathContext"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="synstr:Attribute">
<xsl:param name="paramOverrideNode"/>
<Attribute>
<xsl:for-each select="child::*">
<xsl:choose>
<xsl:when test="fn:name(.)='Value'">
<xsl:apply-templates select=".">
<xsl:with-param name="paramOverrideNode" select="$paramOverrideNode"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</Attribute>
</xsl:template>
<xsl:template match="synstr:Value">
<xsl:param name="paramOverrideNode"/>
<xsl:variable name="varParentName" select="local-name(parent::*)"/>
<xsl:variable name="varParentTermName" select="../../synstr:Term"/>
<xsl:variable name="varTermName" select="../synstr:Term"/>
<!--xsl:if test="../../synstr:Name = 'STANDARD ITEM IDENTIFICATION'">
<xsl:message>
paramOverrideNode: <xsl:copy-of select="$paramOverrideNode"/>
Parent: <xsl:value-of select="$varParentName"/>
Term: <xsl:value-of select="$varTermName"/>
Parent Term: <xsl:value-of select="$varParentTermName"/>
</xsl:message>
</xsl:if-->
<xsl:choose>
<xsl:when test="$paramOverrideNode">
<xsl:variable name="varOverrideNode_ValueType" select="$paramOverrideNode/child::*/processing-instruction('ValueType')"/>
<xsl:variable name="varOverrideNode_Value">
<xsl:choose>
<xsl:when test="$varParentName = 'Attribute'">
<xsl:variable name="varAttributeNameXPath">
<xsl:variable name="xpathTerm" select="concat('/', $varParentTermName, '/@', $varTermName)"/>
<xsl:variable name="xpathTermNsPrefix" select="substring-before($varParentTermName, ':')"/>
<!--Added translate function to solve bug with invoice raw XML from Peppol primary source file-->
<xsl:variable name="xpathTermNs" select="translate($varTermNs[@prefix=$xpathTermNsPrefix],'&quot;','')"/>
<!--xsl:variable name="xpathTermNs" select="translate($varTermNs[@prefix=$xpathTermNsPrefix],'&quot;','')"/-->
<xsl:value-of select="replace( $xpathTerm, concat($xpathTermNsPrefix, ':'), concat('Q{', $xpathTermNs, '}') )"/>
</xsl:variable>
<xsl:if test="$varAttributeNameXPath != ''">
<xsl:variable name="varAttributeValue" as="xs:string?">
<xsl:evaluate xpath="$varAttributeNameXPath" context-item="$paramOverrideNode"/>
</xsl:variable>
<!--xsl:if test="../../synstr:Name = 'STANDARD ITEM IDENTIFICATION'">
<xsl:message>
varAttributeNameXPath: <xsl:value-of select="$varAttributeNameXPath"/>
varAttributeValue: <xsl:value-of select="$varAttributeValue"/>
</xsl:message>
</xsl:if-->
<xsl:value-of select="$varAttributeValue"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$paramOverrideNode/child::*/child::text()[1]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<Value>
<xsl:choose>
<xsl:when test="$varOverrideNode_ValueType!=''">
<xsl:attribute name="type">
<xsl:value-of select="normalize-space($varOverrideNode_ValueType)"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="@type!=''">
<xsl:attribute name="type">
<xsl:value-of select="@type"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="type">
<xsl:value-of select="'EXAMPLE'"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="normalize-space($varOverrideNode_Value)"/>
</Value>
</xsl:when>
<xsl:when test="normalize-space($paramOverrideNode) != ''">
<xsl:value-of select="normalize-space($paramOverrideNode)"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}">
Expand All @@ -186,4 +316,4 @@
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
</xsl:stylesheet>

0 comments on commit 1779cd8

Please sign in to comment.