XSL stylesheet ignores node

68 views Asked by At

Given the following XML:

<ROOT>
    <PROC>
        <DATA>
            <Strength>5</Strength>
            <Procedure_Number>DK</Procedure_Number>
            <Registration_Number>27754</Registration_Number>
            <Trademark>product a</Trademark>
            <Holder>holder a</Holder>
            <Country_Name>Finland</Country_Name>
            <Speciality_Number>002</Speciality_Number>
        </DATA>
    </PROC>
    <PROC>
        <DATA>
            <Strength>10</Strength>
            <Procedure_Number>DK</Procedure_Number>
            <Registration_Number>42852</Registration_Number>
            <Trademark>product b</Trademark>
            <Holder>holder b</Holder>
            <Country_Name>Sweden</Country_Name>
            <Speciality_Number>003</Speciality_Number>
        </DATA>
    </PROC>
    <PROC>
        <DATA>
            <Strength>10</Strength>
            <Procedure_Number>DK</Procedure_Number>
            <Registration_Number>72665</Registration_Number>
            <Trademark>product c</Trademark>
            <Holder>holder c</Holder>
            <Country_Name>Spain</Country_Name>
            <Speciality_Number>004</Speciality_Number>
        </DATA>
    </PROC>
    <PROC>
        <DATA>
            <Strength>10</Strength>
            <Procedure_Number>DK</Procedure_Number>
            <Registration_Number>01948/009|01948/010|01948/011</Registration_Number>
            <Trademark>product b</Trademark>
            <Holder>holder d</Holder>
            <Country_Name>Slovenia</Country_Name>
            <Speciality_Number>003</Speciality_Number>
        </DATA>
    </PROC>
</ROOT>

Should be transformed into the following XML:

<imi:data xmlns:imi="http://www.imi.org/schxox/imi-data/1.0/">
    <coc:eu_ap_form xmlns:coc="http://www.xox.mim/coc/" xmlns:rdm="http://www.xox.mim/dictionary/" xmlns:xsi="http://www.w3.org/2001/XMLSchxoxinstance" xsi:schxoxLocation="http://www.xox.mim/coc/vas.xsd">
        <coc:envelope>
            <rdm:wsurl>http://mim.xox.europa.eu/mim/services/</rdm:wsurl>
            <rdm:formVersion>1.20.0.1</rdm:formVersion>
            <rdm:xsdVersion>1.20.0.1</rdm:xsdVersion>
            <rdm:formtype>var</rdm:formtype>
            <rdm:isEditable>true</rdm:isEditable>
        </coc:envelope>
        <coc:vas-form>
            <coc:apInforpption>
                <coc:huppn>1</coc:huppn>
                <coc:cvol>0</coc:cvol>
                <coc:nationalAuthInMRP>1</coc:nationalAuthInMRP>
                <coc:euAuthorisation>0</coc:euAuthorisation>
                <coc:nationalAuthorisation>0</coc:nationalAuthorisation>
                <coc:procedureNumbers>
                    <coc:procedureNumber/>
                </coc:procedureNumbers>
                <coc:country>Denmark</coc:country>
                <coc:states>
                    <coc:state>Finland</coc:state>
                </coc:states>
                <coc:states>
                    <coc:state>Sweden</coc:state>
                </coc:states>
                <coc:states>
                    <coc:state>Spain</coc:state>
                </coc:states>
                <coc:states>
                    <coc:state>Slovenia</coc:state>
                </coc:states>
                <coc:inventedName/>
            </coc:apInforpption>
            <coc:productsConcerned>
                <coc:products>
                    <coc:formAndStrengthFlag>0</coc:formAndStrengthFlag>
                    <coc:footnote/>
                    <coc:redbox>
                        <coc:vaNumber>002</coc:vaNumber>
                        <coc:blueBox>
                            <coc:memberState>Finland</coc:memberState>
                            <coc:greenBox>
                                <coc:ppNumbers>
                                    <coc:ppNumber>27754</coc:ppNumber>
                                </coc:ppNumbers>
                                <coc:inventedName>product a</coc:inventedName>
                                <coc:ppHolderName>holder a</coc:ppHolderName>
                                <coc:test-form-name/>
                                <coc:strength>5</coc:strength>
                                <coc:units/>
                            </coc:greenBox>
                        </coc:blueBox>
                    </coc:redbox>
                    <coc:redbox>
                        <coc:vaNumber>003</coc:vaNumber>
                        <coc:blueBox>
                            <coc:memberState>Sweden</coc:memberState>
                            <coc:greenBox>
                                <coc:ppNumbers>
                                    <coc:ppNumber>42852</coc:ppNumber>
                                </coc:ppNumbers>
                                <coc:inventedName>product b</coc:inventedName>
                                <coc:ppHolderName>holder b</coc:ppHolderName>
                                <coc:test-form-name/>
                                <coc:strength>10</coc:strength>
                                <coc:units/>
                            </coc:greenBox>
                        </coc:blueBox>
                        <coc:blueBox>
                            <coc:memberState>Slovenia</coc:memberState>
                            <coc:greenBox>
                                <coc:ppNumbers>
                                    <coc:ppNumber>01948/009</coc:ppNumber>
                                </coc:ppNumbers>
                                <coc:ppNumbers>
                                    <coc:ppNumber>01948/010</coc:ppNumber>
                                </coc:ppNumbers>
                                <coc:ppNumbers>
                                    <coc:ppNumber>01948/011</coc:ppNumber>
                                </coc:ppNumbers>
                                <coc:inventedName>product b</coc:inventedName>
                                <coc:ppHolderName>holder d</coc:ppHolderName>
                                <coc:test-form-name/>
                                <coc:strength>10</coc:strength>
                                <coc:units/>
                            </coc:greenBox>
                        </coc:blueBox>
                    </coc:redbox>
                    <coc:redbox>
                        <coc:vaNumber>004</coc:vaNumber>
                        <coc:blueBox>
                            <coc:memberState>Spain</coc:memberState>
                            <coc:greenBox>
                                <coc:ppNumbers>
                                    <coc:ppNumber>72665</coc:ppNumber>
                                </coc:ppNumbers>
                                <coc:inventedName>product c</coc:inventedName>
                                <coc:ppHolderName>holder c</coc:ppHolderName>
                                <coc:test-form-name/>
                                <coc:strength>10</coc:strength>
                                <coc:units/>
                            </coc:greenBox>
                        </coc:blueBox>
                    </coc:redbox>
                </coc:products>
            </coc:productsConcerned>
        </coc:vas-form>
    </coc:eu_ap_form>
    <FSTEMPLATE_>/Applications/mimForms/1.20/Forms/var/Form/va.xdp</FSTEMPLATE_>
    <FSFORMQUERY_>/Applications/mimForms/1.20/Forms/var/Form/va.xdp</FSFORMQUERY_>
    <FSTRANSFORMATIONID_>PDFForm</FSTRANSFORMATIONID_>
    <FSTARGETURL_/>
    <FSAWR_/>
    <FSWR_/>
    <FSCRURI_>repository://</FSCRURI_>
    <FSBASEURL_/>
</imi:data>

So far I tried it out with the following xml stylesheet:

        <?xml version="1.0" encoding="UTF-8"?>

        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:imi="http://www.imi.org/schxox/imi-data/1.0/"
            xmlns:coc="http://www.xox.mim/coc/"
            xmlns:rdm="http://www.xox.mim/dictionary/"
            xmlns:xsi="http://www.w3.org/2001/XMLSchxoxinstance">

        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>  
            <xsl:param name="ns-prefix" select="'imi'"/>
            <xsl:param name="ns-namespace" select="'http://www.imi.org/schxox/imi-data/1.0/'"/>
            <xsl:param name="ns-prefix1" select="'coc'"/>
            <xsl:param name="ns-namespace1" select="'http://www.xox.mim/coc/'"/>
            <xsl:param name="ns-prefix2" select="'rdm'"/>
            <xsl:param name="ns-namespace2" select="'http://www.xox.mim/dictionary/'"/>
            <xsl:param name="ns-prefix3" select="'xsi'"/>
            <xsl:param name="ns-namespace3" select="'http://www.w3.org/2001/XMLSchxoxinstance'"/>
            <xsl:param name="ns-prefix4" select="'schxoxLocation'"/>
            <xsl:param name="ns-namespace4" select="'http://www.xox.mim/coc/vas.xsd'"/>
            <xsl:param name="ns-schxox" select="'http://www.xox.mim/coc/vas.xsd'"/>
            <xsl:variable name="vRdm" select="document('')/*/namespace::*[name()='rdm']"/>
            <xsl:variable name="vXsi" select="document('')/*/namespace::*[name()='xsi']"/>
            <xsl:variable name="vSchxoxLocation" select="document('')/*/namespace::*[name()='schxoxLocation']"/>

     <xsl:template match="/">
        <xsl:element name="{$ns-prefix}:data" namespace="{$ns-namespace}">
            <xsl:element name="{$ns-prefix1}:eu_ap_form" namespace="{$ns-namespace1}">
                <xsl:copy-of select="$vRdm"/>
                <xsl:copy-of select="$vXsi"/>
                <xsl:copy-of select="$vSchxoxLocation"/>
                <xsl:attribute name="xsi:schxoxLocation">
                    <xsl:value-of select="$ns-schxox" />
                </xsl:attribute>
                    <xsl:element name="{$ns-prefix1}:envelope">
                        <xsl:element name="{$ns-prefix1}:wsurl">http://mim.xox.europa.eu/mim/services/</xsl:element>
                        <xsl:element name="{$ns-prefix1}:formVersion" >1.20.0.1</xsl:element>
                        <xsl:element name="{$ns-prefix1}:xsdVersion" >1.20.0.1</xsl:element>
                        <xsl:element name="{$ns-prefix1}:formtype" >var</xsl:element>
                        <xsl:element name="{$ns-prefix1}:isEditable" >true</xsl:element>
                    </xsl:element>

                <xsl:template match="/">    
                    <coc:vas-form>


                    <xsl:element name="{$ns-prefix1}:apInformation">

                            <xsl:element name="{$ns-prefix1}:human">1</xsl:element>
                            <xsl:element name="{$ns-prefix1}:cvol">0</xsl:element>
                            <xsl:element name="{$ns-prefix1}:nationalAuthInMRP">1</xsl:element>
                            <xsl:element name="{$ns-prefix1}:euAuthorisation">0</xsl:element>
                            <xsl:element name="{$ns-prefix1}:nationalAuthorisation">0</xsl:element>

                            <xsl:element name="{$ns-prefix1}:procedureNumbers">
                                <xsl:element name="{$ns-prefix1}:procedureNumber"></xsl:element>
                            </xsl:element>
<xsl:template match="/">
                            <xsl:element name="{$ns-prefix1}:country">
                                <xsl:choose>
                                    <xsl:when test="ROOT/PROC/DATA/Procedure_Number[contains(text(),'DK')]">
                                        <xsl:text>Denmark</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="ROOT/PROC/DATA/Procedure_Number[contains(text(),'SI')]">
                                        <xsl:text>Slovenia</xsl:text>
                                    </xsl:when>
                                </xsl:choose>
                            </xsl:element>
                        </xsl:template>
<xsl:template match="/" mode="toc">
<xsl:for-each select="//Country_Name[not(.=preceding::*)]">
      <coc:states>
          <coc:state><xsl:value-of select="."/></coc:state>
      </coc:states>   
</xsl:for-each>            
</xsl:template>

</xsl:element>

                             <xsl:key name="grp" match="ROOT/PROC/DATA" use="Speciality_Number"/>

<xsl:template match="/ROOT"> 

    <main>
        <!-- create a group for each distinct Number -->
        <xsl:for-each select="ROOT/PROC/DATA[generate-id() = generate-id(key('grp', Speciality_Number)[1])]">

            <coc:redBox>
                <vNumber>
                    <xsl:value-of select="Speciality_Number"/>
                </vNumber>
                <!-- for each member of the current group  -->
                <xsl:for-each select="key('grp', Speciality_Number)">
                    <coc:blueBox>
                        <memberState>
                            <xsl:value-of select="Country_Name"/>
                        </memberState>
                        <coc:greenBox>
                            <ppNumbers>
                                <xsl:copy-of select="Registration"/>
                            </ppNumbers>
                              <inventedName>
                                <xsl:copy-of select="Trademark"/>
                            </inventedName>
                            <ppHolderName>
                                <xsl:copy-of select="Holder"/>
                            </ppHolderName>
                              <strength>
                                <xsl:copy-of select="Strength"/>
                            </strength>
                        </coc:greenBox>
                    </coc:blueBox>
                 </xsl:for-each>    
             </coc:redBox> 
        </xsl:for-each>   
    </main> 
</xsl:template>      

                </coc:vas-form> 
            </xsl:template> 


                </xsl:element>
        <xsl:element name="FSTEMPLATE_">/Applications/mimForms/1.20/Forms/var/Form/va.xdp
                </xsl:element>
                <xsl:element name="FSFORMQUERY_">/Applications/mimForms/1.20/Forms/var/Form/va.xdp
                </xsl:element>
                <xsl:element name="FSTRANSFORMATIONID_">PDFForm</xsl:element>
                <xsl:element name="FSTARGETURL_"/>
                <xsl:element name="FSAWR_"/>
                <xsl:element name="FSWR_"/>
                <xsl:element name="FSCRURI_">repository://</xsl:element>
                <xsl:element name="FSBASEURL_"/>        
        </xsl:element>

    </xsl:template>
</xsl:stylesheet>

I'm facing two problems:

  1. The doc:redBox part (Muenchian) is completely ignored. Alone this part works but included in the rest of the stylesheet i does not. Is it because of the template rules? If yes how can I amend the xml to avoid this problem? Or must the given xml be amended?

  2. Some node content data (Registration_Number) in the given xml is shown as one in one node only divided with "|". How is it possibly to divide each value inside the doc:redBox part an own node as shown in the target xml?

Thank you in advance for your help!

1

There are 1 answers

2
michael.hor257k On BEST ANSWER

Try this as your starting point:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:imi="http://www.imi.org/schxox/imi-data/1.0/"
xmlns:coc="http://www.xox.mim/coc/"
xmlns:rdm="http://www.xox.mim/dictionary/"
xmlns:xsi="http://www.w3.org/2001/XMLSchxoxinstance">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>  

<xsl:key name="grp" match="DATA" use="Speciality_Number"/>

<xsl:template match="/ROOT">
    <imi:data>
        <coc:eu_ap_form xsi:schxoxLocation="http://www.xox.mim/coc/vas.xsd">
            <coc:envelope>
                <rdm:wsurl>http://mim.xox.europa.eu/mim/services/</rdm:wsurl>
                <rdm:formVersion>1.20.0.1</rdm:formVersion>
                <rdm:xsdVersion>1.20.0.1</rdm:xsdVersion>
                <rdm:formtype>var</rdm:formtype>
                <rdm:isEditable>true</rdm:isEditable>
            </coc:envelope>
            <coc:vas-form>
                <coc:apInforpption>
                    <coc:huppn>1</coc:huppn>
                    <coc:cvol>0</coc:cvol>
                    <coc:nationalAuthInMRP>1</coc:nationalAuthInMRP>
                    <coc:euAuthorisation>0</coc:euAuthorisation>
                    <coc:nationalAuthorisation>0</coc:nationalAuthorisation>
                    <coc:procedureNumbers>
                        <coc:procedureNumber/>
                    </coc:procedureNumbers>
                    <coc:country>Denmark</coc:country>

                    <!-- TOC -->
                    <xsl:apply-templates select="PROC/DATA" mode="toc"/>

                    <coc:inventedName/>
                </coc:apInforpption>
                <coc:productsConcerned>
                    <coc:products>
                        <coc:formAndStrengthFlag>0</coc:formAndStrengthFlag>
                        <coc:footnote/>  

                        <!-- APPLY TEMPLATES TO EACH DISTINCT DATA -->
                        <xsl:apply-templates select="PROC/DATA[generate-id() = generate-id(key('grp', Speciality_Number)[1])]" mode="grp"/>

                    </coc:products>
                </coc:productsConcerned>
            </coc:vas-form>
        </coc:eu_ap_form>
        <FSTEMPLATE_>/Applications/mimForms/1.20/Forms/var/Form/va.xdp</FSTEMPLATE_>
        <FSFORMQUERY_>/Applications/mimForms/1.20/Forms/var/Form/va.xdp</FSFORMQUERY_>
        <FSTRANSFORMATIONID_>PDFForm</FSTRANSFORMATIONID_>
        <FSTARGETURL_/>
        <FSAWR_/>
        <FSWR_/>
        <FSCRURI_>repository://</FSCRURI_>
        <FSBASEURL_/>
    </imi:data>
</xsl:template> 

<xsl:template match="DATA" mode="toc">
    <coc:states>
        <coc:state>
            <xsl:value-of select="Country_Name" />
        </coc:state>
    </coc:states>
</xsl:template>    

<xsl:template match="DATA" mode="grp">
    <coc:redbox>
        <coc:vaNumber>
            <xsl:value-of select="Speciality_Number" />
        </coc:vaNumber>
        <!-- APPLY TEMPLATES TO EACH MEMEBR OF THE CURRENT GROUP -->
        <xsl:apply-templates select="key('grp', Speciality_Number)"/>             
    </coc:redbox>
</xsl:template>   

<xsl:template match="DATA">
    <coc:blueBox>
        <coc:memberState>
            <xsl:value-of select="Country_Name" />
        </coc:memberState>
        <coc:greenBox>
            <coc:ppNumbers>
                <coc:ppNumber>
                    <xsl:value-of select="Registration_Number" />
                </coc:ppNumber>
            </coc:ppNumbers>
            <coc:inventedName>
                <xsl:value-of select="Trademark" />
            </coc:inventedName>
            <coc:ppHolderName>
                <xsl:value-of select="Holder" />            
            </coc:ppHolderName>
            <coc:test-form-name/>
            <coc:strength>
                <xsl:value-of select="Strength" />          
            </coc:strength>
            <coc:units/>
        </coc:greenBox>
    </coc:blueBox>
</xsl:template>  

</xsl:stylesheet>

With regard to your second question, do a search for tokenize.