Hello to all,

Please some help with this. I'm newbie to XML, XLS, Xpath, etc.

How can I set correctly the reference in the command "for-each select" to avoid issues with this Top node that has namespace?

I'm trying to get a XLS stylesheet to get some values. The issue is that the Top node has a colon ":" in its name
"doc-master:DOCMASTER1". Searching I've seen that this is named namespaces, where the prefix is doc-master and the
local name is DOCMASTER1.

To begin practice with something simple I'm trying to get values for BicCode and URMs that are children of AMBic.

The XML input is:

<?xml version="1.0" encoding="UTF-8"?>
<doc-master:DOCMASTER1 xmlns="http://www.xyz.com/DOC-MASTER-1" xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1" xmlns:sub-doc="http://www.xyz.com/sub-doc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xyz.com/DOC-MASTER-1 DOC-MASTER.xsd">
  <DOCHEADER>
    <InitialHour>15:22:01</InitialHour>
    <Code>RTPPD</Code>
    <Release>G5.3</Release>
  </DOCHEADER>
  <AMBic>
    <BicCode>87637-YTIT672-12</BicCode>
    <URMs>778-00012</URMs>
  </AMBic>
</doc-master:DOCMASTER1>

The XSL code I'm trying is below, but is failing:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
      <xsl:for-each select="doc-master:DOCMASTER1/AMBic">
      <tr>
        <td><xsl:value-of select="BicCode" /></td>
        <td><xsl:value-of select="URMs" /></td>
      </tr>
      </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Thanks in advance for any help

do not use for each

use the template

<?xml version="1.0" encoding="UTF-8"?>
<doc-master:DOCMASTER1 xmlns="http://www.xyz.com/DOC-MASTER-1" xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1" xmlns:sub-doc="http://www.xyz.com/sub-doc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xsi:schemaLocation="http://www.xyz.com/DOC-MASTER-1 DOC-MASTER.xsd">
    <DOCHEADER>
        <InitialHour>15:22:01</InitialHour>
        <Code>RTPPD</Code>
        <Release>G5.3</Release>
    </DOCHEADER>
    <AMBic>
        <BicCode>87637-YTIT672-12</BicCode>
        <URMs>778-00012</URMs>
    </AMBic>
    <AMBic>
        <BicCode>87637-YTIT672-12</BicCode>
        <URMs>778-00012</URMs>
    </AMBic>
</doc-master:DOCMASTER1>



<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1">
    <xsl:output indent="yes" method="html"/>
    <xsl:template match="/">
        <html>
            <table border="soldid red">
                <xsl:apply-templates select="doc-master:DOCMASTER1"/>
            </table>
        </html>
    </xsl:template>
    <xsl:template match="doc-master:DOCMASTER1">
        <tr>
            <th>BicCode</th>
            <th>URMs</th>
        </tr>
        <xsl:apply-templates select="doc-master:AMBic"/>
    </xsl:template>
    <xsl:template match="doc-master:AMBic">
        <tr>
            <xsl:apply-templates select="doc-master:BicCode"/>
            <xsl:apply-templates select="doc-master:URMs"/>
        </tr>
    </xsl:template>
    <xsl:template match="doc-master:BicCode">
        <td>
            <xsl:value-of select="."/>
        </td>
    </xsl:template>
    <xsl:template match="doc-master:URMs">
        <td>
            <xsl:value-of select="."/>
        </td>
    </xsl:template>
</xsl:stylesheet>

result

<html xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1">
  <table border="soldid red">
    <tr>
      <th>BicCode</th>
      <th>URMs</th>
    </tr>
    <tr>
      <td>87637-YTIT672-12</td>
      <td>778-00012</td>
    </tr>
    <tr>
      <td>87637-YTIT672-12</td>
      <td>778-00012</td>
    </tr>
  </table>
</html>

Edited 2 Years Ago by xml_looser: false copy past

Hello xml looser,

Thanks for your answer and help. I've been trying your solution and works fine.

I was trying with an input file with more inner nodes, but I'm not able to get how to extract the deeper nodes's values.

For the following input (sligthly modification of first xml input file):

<?xml version="1.0" encoding="UTF-8"?>
<doc-master:DOCMASTER1 xmlns="http://www.xyz.com/DOC-MASTER-1" xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1" xmlns:sub-doc="http://www.xyz.com/sub-doc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xsi:schemaLocation="http://www.xyz.com/DOC-MASTER-1 DOC-MASTER.xsd">
    <DOCHEADER>
        <InitialHour>15:22:01</InitialHour>
        <Code>RTPPD</Code>
        <Release>G5.3</Release>
    </DOCHEADER>
    <AMBic>
        <BicCode>87637-YTIT672-12</BicCode>
        <URMs>778-00012</URMs>
        <SUIP>
            <REM-TY>HFY</REM-TY>
            <REM-TZ>
                <A>
                    <B>
                        <C>
                            <Rnah1>889.34</Rnah1>
                            <Rnah2>992.18</Rnah2>
                        </C>
                    </B>
                </A>
            </REM-TZ>
        </SUIP>
    </AMBic>
    <AMBic>
        <BicCode>87637-YTIT672-12</BicCode>
        <URMs>778-00012</URMs>
    </AMBic>
</doc-master:DOCMASTER1>

I want to the get the same values as before and and the new ones, "REM-TY", "Rnah1" and "Rnah2" and I've modified your stylesheet but is not working.

May you help me saying how would be the correct way to do it please.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1">
    <xsl:output indent="yes" method="html"/>
    <xsl:template match="/">
        <html>
            <table border="soldid red">
                <xsl:apply-templates select="doc-master:DOCMASTER1"/>
            </table>
        </html>
    </xsl:template>
    <xsl:template match="doc-master:DOCMASTER1">
        <tr>
            <th>BicCode</th>
            <th>URMs</th>
            <th>REM-TY</th>
            <th>Rnah1</th>
            <th>Rnah2</th>
        </tr>
        <xsl:apply-templates select="doc-master:AMBic"/>
    </xsl:template>
    <xsl:template match="doc-master:AMBic">
        <tr>
            <xsl:apply-templates select="doc-master:BicCode"/>
            <xsl:apply-templates select="doc-master:URMs"/>
            <xsl:apply-templates select="doc-master:SUIP/REM-TY"/>
            <xsl:apply-templates select="doc-master:SUIP/REM-TZ/A/B/C/Rnah1"/>
            <xsl:apply-templates select="doc-master:SUIP/REM-TZ/A/B/C/Rnah2"/>
        </tr>
    </xsl:template>
    <xsl:template match="doc-master:BicCode">
        <td>
            <xsl:value-of select="."/>
        </td>
    </xsl:template>
    <xsl:template match="doc-master:URMs">
        <td>
            <xsl:value-of select="."/>
        </td>
    </xsl:template>
    <xsl:template match="doc-master:SUIP/REM-TY">
        <td>
            <xsl:value-of select="."/>
        </td>
    </xsl:template>  
        <xsl:template match="doc-master:SUIP/REM-TZ/A/B/C/Rnah1">
        <td>
            <xsl:value-of select="."/>
        </td>
    </xsl:template>  
        <xsl:template match="doc-master:SUIP/REM-TZ/A/B/C/Rnah2">
        <td>
            <xsl:value-of select="."/>
        </td>
    </xsl:template>  
</xsl:stylesheet>

Thank in advance for the help.

Regards

Edited 2 Years Ago by Garidius: Fixing format

show more of the original xml file
and what should be applied

more nodes help to better understand the problem

Hello again,

Thanks for trying to help me.

Below is a better and most complete original input xml file, for which I want to get all values. Many of them are children of children.

Below the Input xml file, I show the output I'd like to get (I edited this output manually). If you see the output as html in an explorer, you'll se that I want to print the first 2 rows to indicate the parent of the 4 nodes "C","ND", "SNStr","SNStp". This because these 4 nodes are children of MNr and GTRn, and MNr and GTRn are children of CENs1.

I hope is not too complicate.

Thanks in advance for your help and time.

Input xml:

<?xml version="1.0" encoding="UTF-8"?>
<doc-master:DOCMASTER1 xmlns="http://www.xyz.com/DOC-MASTER-1" xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1" xmlns:sub-doc="http://www.xyz.com/sub-doc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xsi:schemaLocation="http://www.xyz.com/DOC-MASTER-1 DOC-MASTER.xsd">
    <DOCHEADER>
        <InitialHour>07:34:11</InitialHour>
        <Code>Mdj-00Kld</Code>
        <Release>5.9</Release>
    </DOCHEADER>
  <OInf>
    <ONam>JOSKL-002</ONam>
    <Cini>LLOP</Cini>
    <NLst>
      <Ntk>
        <Tco>UUTO772</Tco>
        <NtkType>OOWWP</NtkType>
        <NtkData>
          <RInf>
            <EdCh>2009-11-21</EdCh>
            <CENs1>
              <MNr>
                <RDt>
                  <NRn>
                    <C>546</C>
                    <ND>723</ND>
                    <SNRn>
                      <SNStr>727</SNStr>
                      <SNStp>732</SNStp>
                    </SNRn>
                  </NRn>
                </RDt>
                <RDt>
                  <NRn>
                    <C>546</C>
                    <ND>723</ND>
                    <SNRn>
                      <SNStr>729</SNStr>
                      <SNStp>734</SNStp>
                    </SNRn>
                  </NRn>
                </RDt>
              </MNr>
              <GTRn>
                <RDt>
                  <NRn>
                    <C>546</C>
                    <ND>723</ND>
                    <SNRn>
                      <SNStr>802</SNStr>
                      <SNStp>865</SNStp>
                    </SNRn>
                  </NRn>
                </RDt>
              </GTRn>
            </CENs1>
            <CENs2>
              <MC>5998</MC>
              <MN>2113</MN>
            </CENs2>
          </RInf>
        </NtkData>
      </Ntk>
    </NLst>
  </OInf>
    <DOCHEADER>
        <InitialHour>11:22:03</InitialHour>
        <Code>HXT-0992</Code>
        <Release>4.7</Release>
    </DOCHEADER>  
  <OInf>
    <ONam>LOKLP01</ONam>
    <Cini>KUIEP</Cini>
    <NLst>
      <Ntk>
        <Tco>UYO244</Tco>
        <NtkType>MAAJ</NtkType>
        <NtkData>
          <RInf>
            <EdCh>2012-05-15</EdCh>
            <CENs1>
              <MNr>
                <RDt>
                  <NRn>
                    <C>336</C>
                    <ND>254</ND>
                    <SNRn>
                      <SNStr>100</SNStr>
                      <SNStp>450</SNStp>
                    </SNRn>
                  </NRn>
                </RDt>
              </MNr>
              <GTRn>
                <RDt>
                  <NRn>
                    <C>336</C>
                    <ND>254</ND>
                    <SNRn>
                      <SNStr>750</SNStr>
                      <SNStp>999</SNStp>
                    </SNRn>
                  </NRn>
                </RDt>
              </GTRn>
            </CENs1>
            <CENs2>
              <MC>5998</MC>
              <MN>2113</MN>
            </CENs2>
          </RInf>
        </NtkData>
      </Ntk>
    </NLst>
  </OInf>
</doc-master:DOCMASTER1>

Output I'm looking for:

<html xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1">
    <table border="soldid red">
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>CENs1</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>CENs2</td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>MNr</td>
      <td></td>
      <td></td>
      <td></td>
      <td>GTRn</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td>InitialHour</td>
      <td>Code</td>
      <td>Release</td>
      <td>ONam</td>
      <td>Cini</td>
      <td>Tco</td>
      <td>NtkType</td>
      <td>EdCh</td>
      <td>C</td>
      <td>ND</td>
      <td>SNStr</td>
      <td>SNStp</td>
      <td>C</td>
      <td>ND</td>
      <td>SNStr</td>
      <td>SNStp</td>
      <td>MC</td>
      <td>MN</td>
    </tr>
    <tr>
      <td>07:34:11</td>
      <td>Mdj-00Kld</td>
      <td>5.9</td>
      <td>JOSKL-002</td>
      <td>LLOP</td>
      <td>UUTO772</td>
      <td>OOWWP</td>
      <td>2009-11-21</td>
      <td>546</td>
      <td>723</td>
      <td>727</td>
      <td>732</td>
      <td>546</td>
      <td>723</td>
      <td>802</td>
      <td>865</td>
      <td>5998</td>
      <td>2113</td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>546</td>
      <td>723</td>
      <td>729</td>
      <td>734</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td>11:22:03</td>
      <td>HXT-0992</td>
      <td>4.7</td>
      <td>LOKLP01</td>
      <td>KUIEP</td>
      <td>UYO244</td>
      <td>MAAJ</td>
      <td>2012-05-15</td>
      <td>336</td>
      <td>254</td>
      <td>100</td>
      <td>450</td>
      <td>336</td>
      <td>254</td>
      <td>750</td>
      <td>999</td>
      <td>5998</td>
      <td>2113</td>
    </tr>
    </table>
</html>

I hope it's in your mind

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1">
    <xsl:output indent="yes" method="html"/>
    <xsl:template match="/">
        <xsl:apply-templates select="doc-master:DOCMASTER1"/>
    </xsl:template>
    <xsl:template match="doc-master:DOCMASTER1">
        <html xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1">
            <table border="soldid" bordercolor="red">
                <tr>
                    <td colspan="9"></td>
                    <td>CENs1</td>
                    <td colspan="3"></td>
                    <td>CENs2</td>
                </tr>
                <tr>
                    <td colspan="9"></td>
                    <td>MNr</td>
                    <td colspan="3"></td>
                    <td>GTRn</td>
                </tr>
                <tr>
                    <td>Pos</td>
                    <td>InitialHour</td>
                    <td>Code</td>
                    <td>Release</td>
                    <td>ONam</td>
                    <td>Cini</td>
                    <td>Tco</td>
                    <td>NtkType</td>
                    <td>EdCh</td>
                    <td>C</td>
                    <td>ND</td>
                    <td>SNStr</td>
                    <td>SNStp</td>
                    <td>C</td>
                    <td>ND</td>
                    <td>SNStr</td>
                    <td>SNStp</td>
                    <td>MC</td>
                    <td>MN</td>
                </tr>
                <xsl:apply-templates select="doc-master:DOCHEADER"/>
            </table>
        </html>
    </xsl:template>
    <xsl:template match="doc-master:DOCHEADER">
        <xsl:variable name="pos" select="position()"/>
        <tr>
            <td rowspan="2">
                <xsl:value-of select="$pos"/>
            </td>
            <td rowspan="2">
                <xsl:value-of select="doc-master:InitialHour"/>
            </td>
            <td rowspan="2">
                <xsl:value-of select="doc-master:Code"/>
            </td>
            <td rowspan="2">
                <xsl:value-of select="doc-master:Release"/>
            </td>
            <xsl:apply-templates select="../doc-master:OInf[$pos]"/>
        </tr>
        <tr>
            <xsl:apply-templates select="../doc-master:OInf[$pos]/doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:GTRn"/>
        </tr>
    </xsl:template>
    <xsl:template match="doc-master:OInf">
        <td rowspan="2">
            <xsl:value-of select="doc-master:ONam"/>
        </td>
        <td rowspan="2">
            <xsl:value-of select="doc-master:Cini"/>
        </td>
        <xsl:apply-templates select="doc-master:NLst"/>
    </xsl:template>
    <xsl:template match="doc-master:NLst">
        <td rowspan="2">
            <xsl:value-of select="doc-master:Ntk/doc-master:Tco"/>
        </td>
        <td rowspan="2">
            <xsl:value-of select="doc-master:Ntk/doc-master:NtkType"/>
        </td>
        <xsl:apply-templates select="doc-master:Ntk/doc-master:NtkData"/>
    </xsl:template>
    <xsl:template match="doc-master:NtkData">
        <xsl:apply-templates select="doc-master:RInf"/>
    </xsl:template>
    <xsl:template match="doc-master:RInf">
        <td rowspan="2">
            <xsl:value-of select="doc-master:EdCh"/>
        </td>
        <xsl:apply-templates select="doc-master:CENs1"/>
        <xsl:apply-templates select="doc-master:CENs2"/>
    </xsl:template>
    <xsl:template match="doc-master:CENs1">
        <xsl:apply-templates select="doc-master:MNr"/>

        <xsl:apply-templates select="doc-master:GTRn"/>
    </xsl:template>
    <xsl:template match="doc-master:MNr">
        <td>
            <xsl:value-of select="doc-master:RDt/doc-master:NRn/doc-master:C"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:RDt/doc-master:NRn/doc-master:ND"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:RDt/doc-master:NRn/doc-master:SNRn/doc-master:SNStr"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:RDt/doc-master:NRn/doc-master:SNRn/doc-master:SNStp"/>
        </td>
    </xsl:template>
    <xsl:template match="doc-master:GTRn">
        <td>
            <xsl:value-of select="doc-master:RDt/doc-master:NRn/doc-master:C"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:RDt/doc-master:NRn/doc-master:ND"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:RDt/doc-master:NRn/doc-master:SNRn/doc-master:SNStr"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:RDt/doc-master:NRn/doc-master:SNRn/doc-master:SNStp"/>
        </td>
    </xsl:template>
    <xsl:template match="doc-master:CENs2">
        <td>
            <xsl:value-of select="doc-master:MC"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:MN"/>
        </td>
    </xsl:template>
</xsl:stylesheet>

Edited 2 Years Ago by xml_looser

Hello xml looser,

Thanks for the help. It almost working. Your solution it works parsing as I want all nodes, but is parsing partially the
deeper nodes "C", "ND", "SNStr" and "SNStp".

As you can see, C, ND, SNStr and SNStp are children of "RDt". And Rdt and its children could appear one or more times within
the nodes MNr and GTRn. In this input xml, for the first "<OInf>" node, there are 2 nodes RDt within MNr, so, 2 rows should
appear for values of C, ND, SNRtr, SNStp that belong to MNr. For the GTRn in first "OInf" there is only one block "RDt", then
only one row should appear to fill values of C, ND, SNRtr, SNStp that belong to GTRn.

In the second Oinf block, both nodes MNr and GTRn have only one block "RDt", so, only one row should appear for the second OInf.

I hope make sense and you can help me to fix this part, it seems like a kind of loop could help to get it, but I don't know how
to do it.

For you to see easier, below a I show the same input XML, but with easier values and the corresponding desired output.

Thanks againfor all the help.

XML input:

<?xml version="1.0" encoding="UTF-8"?>
<doc-master:DOCMASTER1 xmlns="http://www.xyz.com/DOC-MASTER-1" xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1" xmlns:sub-doc="http://www.xyz.com/sub-doc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xsi:schemaLocation="http://www.xyz.com/DOC-MASTER-1 DOC-MASTER.xsd">
    <DOCHEADER>
        <InitialHour>07:34:11</InitialHour>
        <Code>Mdj-00Kld</Code>
        <Release>5.9</Release>
    </DOCHEADER>
  <OInf>
    <ONam>JOSKL-002</ONam>
    <Cini>LLOP</Cini>
    <NLst>
      <Ntk>
        <Tco>UUTO772</Tco>
        <NtkType>OOWWP</NtkType>
        <NtkData>
          <RInf>
            <EdCh>2009-11-21</EdCh>
            <CENs1>
              <MNr>
                <RDt>
                  <NRn>
                    <C>1</C>
                    <ND>2</ND>
                    <SNRn>
                      <SNStr>3</SNStr>
                      <SNStp>4</SNStp>
                    </SNRn>
                  </NRn>
                </RDt>
                <RDt>
                  <NRn>
                    <C>5</C>
                    <ND>6</ND>
                    <SNRn>
                      <SNStr>7</SNStr>
                      <SNStp>8</SNStp>
                    </SNRn>
                  </NRn>
                </RDt>
              </MNr>
              <GTRn>
                <RDt>
                  <NRn>
                    <C>9</C>
                    <ND>10</ND>
                    <SNRn>
                      <SNStr>11</SNStr>
                      <SNStp>12</SNStp>
                    </SNRn>
                  </NRn>
                </RDt>
              </GTRn>
            </CENs1>
            <CENs2>
              <MC>100</MC>
              <MN>101</MN>
            </CENs2>
          </RInf>
        </NtkData>
      </Ntk>
    </NLst>
  </OInf>
    <DOCHEADER>
        <InitialHour>11:22:03</InitialHour>
        <Code>HXT-0992</Code>
        <Release>4.7</Release>
    </DOCHEADER>  
  <OInf>
    <ONam>LOKLP01</ONam>
    <Cini>KUIEP</Cini>
    <NLst>
      <Ntk>
        <Tco>UYO244</Tco>
        <NtkType>MAAJ</NtkType>
        <NtkData>
          <RInf>
            <EdCh>2012-05-15</EdCh>
            <CENs1>
              <MNr>
                <RDt>
                  <NRn>
                    <C>13</C>
                    <ND>14</ND>
                    <SNRn>
                      <SNStr>15</SNStr>
                      <SNStp>16</SNStp>
                    </SNRn>
                  </NRn>
                </RDt>
              </MNr>
              <GTRn>
                <RDt>
                  <NRn>
                    <C>17</C>
                    <ND>18</ND>
                    <SNRn>
                      <SNStr>19</SNStr>
                      <SNStp>20</SNStp>
                    </SNRn>
                  </NRn>
                </RDt>
              </GTRn>
            </CENs1>
            <CENs2>
              <MC>200</MC>
              <MN>201</MN>
            </CENs2>
          </RInf>
        </NtkData>
      </Ntk>
    </NLst>
  </OInf>
</doc-master:DOCMASTER1>

XML Output desired:

<html xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1">
    <table border="soldid red">
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>CENs1</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>CENs2</td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>MNr</td>
      <td></td>
      <td></td>
      <td></td>
      <td>GTRn</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td>InitialHour</td>
      <td>Code</td>
      <td>Release</td>
      <td>ONam</td>
      <td>Cini</td>
      <td>Tco</td>
      <td>NtkType</td>
      <td>EdCh</td>
      <td>C</td>
      <td>ND</td>
      <td>SNStr</td>
      <td>SNStp</td>
      <td>C</td>
      <td>ND</td>
      <td>SNStr</td>
      <td>SNStp</td>
      <td>MC</td>
      <td>MN</td>
    </tr>
    <tr>
      <td>07:34:11</td>
      <td>Mdj-00Kld</td>
      <td>5.9</td>
      <td>JOSKL-002</td>
      <td>LLOP</td>
      <td>UUTO772</td>
      <td>OOWWP</td>
      <td>2009-11-21</td>
      <td>1</td>
      <td>2</td>
      <td>3</td>
      <td>4</td>
      <td>9</td>
      <td>10</td>
      <td>11</td>
      <td>12</td>
      <td>100</td>
      <td>101</td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>5</td>
      <td>6</td>
      <td>7</td>
      <td>8</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td>11:22:03</td>
      <td>HXT-0992</td>
      <td>4.7</td>
      <td>LOKLP01</td>
      <td>KUIEP</td>
      <td>UYO244</td>
      <td>MAAJ</td>
      <td>2012-05-15</td>
      <td>13</td>
      <td>14</td>
      <td>15</td>
      <td>16</td>
      <td>17</td>
      <td>18</td>
      <td>19</td>
      <td>20</td>
      <td>200</td>
      <td>201</td>
    </tr>
    </table>
</html>

it is right for me are just data without significant

hope it is right now

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1">
    <xsl:output indent="yes" method="html"/>
    <xsl:template match="/">
        <xsl:apply-templates select="doc-master:DOCMASTER1"/>
    </xsl:template>
    <xsl:template match="doc-master:DOCMASTER1">
        <html xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1">
            <table border="soldid" bordercolor="red">
                <tr>
                    <td colspan="9"></td>
                    <td>CENs1</td>
                    <td colspan="3"></td>
                    <td>CENs2</td>
                </tr>
                <tr>
                    <td colspan="9"></td>
                    <td>MNr</td>
                    <td colspan="3"></td>
                    <td>GTRn</td>
                </tr>
                <tr>
                    <td>Pos</td>
                    <td>InitialHour</td>
                    <td>Code</td>
                    <td>Release</td>
                    <td>ONam</td>
                    <td>Cini</td>
                    <td>Tco</td>
                    <td>NtkType</td>
                    <td>EdCh</td>
                    <td>C</td>
                    <td>ND</td>
                    <td>SNStr</td>
                    <td>SNStp</td>
                    <td>C</td>
                    <td>ND</td>
                    <td>SNStr</td>
                    <td>SNStp</td>
                    <td>MC</td>
                    <td>MN</td>
                </tr>
                <xsl:apply-templates select="doc-master:DOCHEADER"/>
            </table>
        </html>
    </xsl:template>
    <xsl:template match="doc-master:DOCHEADER">
        <xsl:variable name="pos" select="position()"/>
        <tr>
            <td rowspan="2">
                <xsl:value-of select="$pos"/>
            </td>
            <td rowspan="2">
                <xsl:value-of select="doc-master:InitialHour"/>
            </td>
            <td rowspan="2">
                <xsl:value-of select="doc-master:Code"/>
            </td>
            <td rowspan="2">
                <xsl:value-of select="doc-master:Release"/>
            </td>
            <xsl:apply-templates select="../doc-master:OInf[$pos]"/>
        </tr>
        <xsl:if test="../doc-master:OInf[$pos]/doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:MNr/doc-master:RDt[2]">
            <tr>
                <xsl:apply-templates select="../doc-master:OInf[$pos]/doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:MNr/doc-master:RDt[2]"/>
            </tr>
        </xsl:if>
    </xsl:template>
    <xsl:template match="doc-master:OInf">
        <td rowspan="2">
            <xsl:value-of select="doc-master:ONam"/>
        </td>
        <td rowspan="2">
            <xsl:value-of select="doc-master:Cini"/>
        </td>
        <xsl:apply-templates select="doc-master:NLst"/>
    </xsl:template>
    <xsl:template match="doc-master:NLst">
        <td rowspan="2">
            <xsl:value-of select="doc-master:Ntk/doc-master:Tco"/>
        </td>
        <td rowspan="2">
            <xsl:value-of select="doc-master:Ntk/doc-master:NtkType"/>
        </td>
        <xsl:apply-templates select="doc-master:Ntk/doc-master:NtkData"/>
    </xsl:template>
    <xsl:template match="doc-master:NtkData">
        <xsl:apply-templates select="doc-master:RInf"/>
    </xsl:template>
    <xsl:template match="doc-master:RInf">
        <td rowspan="2">
            <xsl:value-of select="doc-master:EdCh"/>
        </td>
        <xsl:apply-templates select="doc-master:CENs1"/>
        <xsl:apply-templates select="doc-master:CENs2"/>
    </xsl:template>
    <xsl:template match="doc-master:CENs1">
        <xsl:apply-templates select="doc-master:MNr/doc-master:RDt[1]"/>

        <xsl:apply-templates select="doc-master:GTRn"/>
    </xsl:template>
    <xsl:template match="doc-master:RDt">

        <td>
            <xsl:value-of select="doc-master:NRn/doc-master:C"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:NRn/doc-master:ND"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:NRn/doc-master:SNRn/doc-master:SNStr"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:NRn/doc-master:SNRn/doc-master:SNStp"/>
        </td>
    </xsl:template>
    <xsl:template match="doc-master:CENs2">
        <td rowspan="2">
            <xsl:value-of select="doc-master:MC"/>
        </td>
        <td rowspan="2">
            <xsl:value-of select="doc-master:MN"/>
        </td>
    </xsl:template>
</xsl:stylesheet>

Hello xml looser,

Thanks for the help. Your last XSL gives correct the output for my last input XML, but the issue is when you add more blocks "RDt" inside the parent block "MNr" or "GTRn". You can try adding the block below within "MNr" and/or within "GTRn" and you'll see that is not appearing in output.

Please insert this block within "MNr" and/or within "GTRn"

                <RDt>
                  <NRn>
                    <C>X</C>
                    <ND>Y</ND>
                    <SNRn>
                      <SNStr>Z</SNStr>
                      <SNStp>W</SNStp>
                    </SNRn>
                  </NRn>
                </RDt>

I hope it is possible to get the output desired.

Thanks again for great help.

It is better from the beginning all testify to inform
so as to save time in order to find the solution
I have too much time consumed for a task

I use this forum as a balancing for my work

is the best way
xml input and the desired output
specify

Helmut Hagemann

ps hope for a response

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:doc-master="http://www.xyz.com/DOC-MASTER-1">
    <xsl:output indent="yes" method="html"/>
    <xsl:template match="/">
        <xsl:apply-templates select="doc-master:DOCMASTER1"/>
    </xsl:template>
    <xsl:template match="doc-master:DOCMASTER1">
        <html>
            <xsl:comment>copyright Helmut Hagemann email xml_user(at)web.de</xsl:comment>
            <table border="solid" borderolor="black">
                <thead>
                    <tr>
                        <th colspan="8" rowspan="2">Analysis</th>
                        <th colspan="8">CENs1</th>
                        <th colspan="2" rowspan="2">CENs2</th>
                    </tr>
                    <tr>
                        <th colspan="4">MNr</th>
                        <th colspan="4">GTRn</th>
                    </tr>
                    <tr>
                        <th>InitialHour</th>
                        <th>Code</th>
                        <th>Release</th>
                        <th>ONam</th>
                        <th>Cini</th>
                        <th>Tco</th>
                        <th>NtkType</th>
                        <th>EdCh</th>
                        <th>C</th>
                        <th>ND</th>
                        <th>SNStr</th>
                        <th>SNStp</th>
                        <th>C</th>
                        <th>ND</th>
                        <th>SNStr</th>
                        <th>SNStp</th>
                        <th>MC</th>
                        <th>MN</th>
                    </tr>
                </thead>
                <xsl:apply-templates select="doc-master:DOCHEADER"/>
            </table>
        </html>
    </xsl:template>
    <xsl:template match="doc-master:DOCHEADER">
        <tr>
            <xsl:call-template name="OInf">
                <xsl:with-param name="ak" select="."/>
                <xsl:with-param name="pos" select="position()"/>
            </xsl:call-template>
        </tr>
    </xsl:template>
    <xsl:template name="OInf">
        <xsl:param name="ak"/>
        <xsl:param name="pos"/>
        <xsl:apply-templates select="$ak/../doc-master:OInf[$pos]">
            <xsl:with-param name="pos" select="$pos"/>
        </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="doc-master:OInf">
        <xsl:param name="pos"/>
        <xsl:variable name="MNr" select="count(.//doc-master:MNr/doc-master:RDt)"/>
        <xsl:variable name="GTRn" select="count(.//doc-master:GTRn/doc-master:RDt)"/>
        <td>
            <xsl:if test="$MNr &gt;= $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$MNr "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="$MNr &lt; $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$GTRn "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:value-of select="../doc-master:DOCHEADER[$pos]/doc-master:InitialHour"/>
        </td>
        <td>
            <xsl:if test="$MNr &gt;= $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$MNr "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="$MNr &lt; $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$GTRn "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:value-of select="../doc-master:DOCHEADER[$pos]/doc-master:Code"/>
        </td>
        <td>
            <xsl:if test="$MNr &gt;= $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$MNr "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="$MNr &lt; $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$GTRn "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:value-of select="../doc-master:DOCHEADER[$pos]/doc-master:Release"/>
        </td>
        <td>
            <xsl:if test="$MNr &gt;= $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$MNr "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="$MNr &lt; $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$GTRn "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:value-of select="doc-master:ONam"/>
        </td>
        <td>
            <xsl:if test="$MNr &gt;= $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$MNr "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="$MNr &lt; $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$GTRn "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:value-of select="doc-master:Cini"/>
        </td>
        <td>
            <xsl:if test="$MNr &gt;= $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$MNr"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="$MNr &lt; $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$GTRn "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:Tco"/>
        </td>
        <td>
            <xsl:if test="$MNr &gt;= $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$MNr"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="$MNr &lt; $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$GTRn "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:NtkType"/>
        </td>
        <td>
            <xsl:if test="$MNr &gt;= $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$MNr"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="$MNr &lt; $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$GTRn "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:EdCh"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:MNr/doc-master:RDt/doc-master:NRn/doc-master:C"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:MNr/doc-master:RDt/doc-master:NRn/doc-master:ND"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:MNr/doc-master:RDt/doc-master:NRn/doc-master:SNRn/doc-master:SNStr"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:MNr/doc-master:RDt/doc-master:NRn/doc-master:SNRn/doc-master:SNStp"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:GTRn/doc-master:RDt/doc-master:NRn/doc-master:C"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:GTRn/doc-master:RDt/doc-master:NRn/doc-master:ND"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:GTRn/doc-master:RDt/doc-master:NRn/doc-master:SNRn/doc-master:SNStr"/>
        </td>
        <td>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:GTRn/doc-master:RDt/doc-master:NRn/doc-master:SNRn/doc-master:SNStp"/>
        </td>
        <td>
            <xsl:if test="$MNr &gt;= $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$MNr"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="$MNr &lt; $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$GTRn "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs2/doc-master:MC"/>
        </td>
        <td>
            <xsl:if test="$MNr &gt;= $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$MNr"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="$MNr &lt; $GTRn">
                <xsl:attribute name="rowspan">
                    <xsl:value-of select="$GTRn "/>
                </xsl:attribute>
            </xsl:if>
            <xsl:value-of select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs2/doc-master:MN"/>
        </td>

        <xsl:if test="$MNr &lt; $GTRn">
            <xsl:apply-templates select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:GTRn" mode="GTRn"/>
        </xsl:if>
        <xsl:if test="$MNr &gt;= $GTRn">
            <xsl:apply-templates select="doc-master:NLst/doc-master:Ntk/doc-master:NtkData/doc-master:RInf/doc-master:CENs1/doc-master:MNr" mode="MNr"/>
        </xsl:if>
    </xsl:template>

    <xsl:template match="doc-master:GTRn" mode="GTRn">
        <xsl:apply-templates select="doc-master:RDt[position()&gt;1]" mode="GTRn">
        </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="doc-master:MNr" mode="MNr">
        <xsl:apply-templates select="doc-master:RDt[position()&gt;1]" mode="MNr">
        </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="doc-master:RDt" mode="GTRn">
        <xsl:variable name="pos" select="position()"/>
        <tr>
            <td>
                <xsl:value-of select="../../doc-master:MNr/doc-master:RDt[$pos+1]/doc-master:NRn/doc-master:C"/>
            </td>
            <td>
                <xsl:value-of select="../../doc-master:MNr/doc-master:RDt[$pos+1]/doc-master:NRn/doc-master:ND"/>
            </td>
            <td>
                <xsl:value-of select="../../doc-master:MNr/doc-master:RDt[$pos+1]/doc-master:NRn/doc-master:SNRn/doc-master:SNStr"/>
            </td>
            <td>
                <xsl:value-of select="../../doc-master:MNr/doc-master:RDt[$pos+1]/doc-master:NRn/doc-master:SNRn/doc-master:SNStp"/>
            </td>
            <td>
                <xsl:value-of select="doc-master:NRn/doc-master:C"/>
            </td>
            <td>
                <xsl:value-of select="doc-master:NRn/doc-master:ND"/>
            </td>
            <td>
                <xsl:value-of select="doc-master:NRn/doc-master:SNRn/doc-master:SNStr"/>
            </td>
            <td>
                <xsl:value-of select="doc-master:NRn/doc-master:SNRn/doc-master:SNStp"/>
            </td>
        </tr>
    </xsl:template>
    <xsl:template match="doc-master:RDt" mode="MNr">
        <xsl:variable name="pos" select="position()"/>
        <tr>
            <td>
                <xsl:value-of select="doc-master:NRn/doc-master:C"/>
            </td>
            <td>
                <xsl:value-of select="doc-master:NRn/doc-master:ND"/>
            </td>
            <td>
                <xsl:value-of select="doc-master:NRn/doc-master:SNRn/doc-master:SNStr"/>
            </td>
            <td>
                <xsl:value-of select="doc-master:NRn/doc-master:SNRn/doc-master:SNStp"/>
            </td>
            <td>
                <xsl:value-of select="../../doc-master:GTRn/doc-master:RDt[$pos+1]/doc-master:NRn/doc-master:C"/>
            </td>
            <td>
                <xsl:value-of select="../../doc-master:GTRn/doc-master:RDt[$pos+1]/doc-master:NRn/doc-master:ND"/>
            </td>
            <td>
                <xsl:value-of select="../../doc-master:GTRn/doc-master:RDt[$pos+1]/doc-master:NRn/doc-master:SNRn/doc-master:SNStr"/>
            </td>
            <td>
                <xsl:value-of select="../../doc-master:GTRn/doc-master:RDt[$pos+1]/doc-master:NRn/doc-master:SNRn/doc-master:SNStp"/>
            </td>
        </tr>
    </xsl:template>
</xsl:stylesheet>

Edited 2 Years Ago by xml_looser: input new

Hello dear Helmut,

Your great for give your time to help others. You have helped me a lot
and sorry for not explain better my desired output from the beginning. I was trying not to bother putting a long input, I was hoping be able to adapt your solution for a simple input to a complex one, but I couldn't. Because of that I needed to modify the input posted.

Your last code works so great! and I'm trying to understand it :)

I don't want you to take more time in this question, only want to know if is there a way to apply your XSLT code for several XMLs in a directory?

If could be easy to do it maybe you can help me with this last help request, if it is time consuming issue, don't worry. I'll apply it one XML each time.

Thanks again.

Best regards

Hello Helmut,

I'm using windows 7. I think in a kind of loop for all XML files in a folder getting a unique output if possible and not to much complicated or time consuming for you.

Thanks again.

Regards

you want to do from many XML files a total XML file and then evaluate with xsl
or
only evaluate the XML and handle all XML xsl generated together
number of xml file in directory

Hallo Helmut,

  • I have in a directory, lets say 100 XML files
  • Each XML file has only one top node called <OInf>.

Join all XML files in a unique XML would be complicated since I would need another kind of script to join all XMLs in a single one with 100 <OInf> nodes inside.

Your XSL stylesheet works fine when I apply it for each XML one by one.

Then, what I have in mind is apply your XSL stylesheet for all XMLs in directory. I mean, set the loop inside the XSL code from XML-1 to XML-N, then XSL code would look the first XML and would process it, generating the HTML output as currently does (thi would be the first row of the output table).

Then XSL would look for the 2nd XML input and would process it, generating the html output for the 2nd XML. This 2nd output would be appended to the first output. So, the 2nd output would be the 2nd row of the output table.

Then continue in the same way up to the 100 XML files, obtaining a unique HTML ouput table containing 100 rows, each row corresponding to the output of each XML input.

Maybe is possible adding a loop withing your code, but if you think could be a lot of work, please only suggest me if the loop should be done in another language to apply your XLS code as convertion template.

I hope make sense.

Vielen dank nochmals für ihre große hilfe

Mit besten Grüßen

This article has been dead for over six months. Start a new discussion instead.