2

I have tried converting the following XML to another XML document using the XSLT style sheet I have created. The output is not giving me what i want, the output is not the right xml nodes nor is it outputting the tags.

Please could someone help.

The XML File to be transformed looks like this:

    <?xml version="1.0" encoding="utf-8"?>
      <Extract xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         <Header>
           <SubscriptionName>Auto_Clients</SubscriptionName>
           <SubscriptionID>1731</SubscriptionID>
           <ExecutionID>11987</ExecutionID>
           <ODIFeed>Clients</ODIFeed>
           <DataDateTime>2013-07-22T13:53:49</DataDateTime>
           <FirmCodes>
             <FirmCode>ZR</FirmCode>
           </FirmCodes>
           <Environment>INTEGRATION</Environment>
           <NoOfRecords>1</NoOfRecords>
          </Header>
          <Clients>
           <Client>
            <FirmCode>ZR</FirmCode>
            <ClientReference>ZR1071049</ClientReference>
            <ClientType>02</ClientType>
            <ShortName>ZRTEST</ShortName>
            <FullName>CLTTEST</FullName>
           </Client>
          </Clients>
       </Extract>

The XSLT StyleSheet I have created is this

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     version="1.0">
     <xsl:output method="xml"  indent="yes"/>
       <xsl:template match="table">
        <Clients>
          <xsl:for-each select="Client">
          <Client>
           <FirmCode>
              <xsl:value-of select="FirmCode" />
           </FirmCode>
           <ClientReference>
              <xsl:value-of select="ClientReference" />
           </ClientReference>
           <ClientType>
              <xsl:value-of select="ClientType" />
           </ClientType>
           <ShortName>
              <xsl:value-of select="ShortName" />
           </ShortName>
           <FullName>
              <xsl:value-of select="FullName" />
           </FullName>
        </Client>
       </xsl:for-each>
      </Clients>
     </xsl:template>
    </xsl:stylesheet>

My Desired output is something like:

    <Clients>
      <Client>
        <FirmCode>ZR</FirmCode>
        <ClientReference>ZR1071049</ClientReference>
        <FullName>CLTTEST</FullName>
      </Client>
    </Clients>
DManDev
  • 33
  • 1
  • 5

1 Answers1

3

There is no table element in your input so your template matches nothing and is never executed. What you see is purely the result of applying the built-in template rules.

You need to change:

<xsl:template match="table">

to:

<xsl:template match="Extract">

Also change:

<xsl:for-each select="Client">

to:

<xsl:for-each select="Clients/Client">

because Client is not a child of Extract.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • This has not changed the output, for some reason the output i am getting is text, with all the node data being outputted not just the select nodes i am interested in, also no tags are output either. – DManDev Apr 11 '17 at 08:04
  • No, the problem is something else - see: http://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-root-node/34762628#34762628 – michael.hor257k Apr 11 '17 at 14:07