We help IT Professionals succeed at work.

XSLT need a couple of fields added + quickie tutorial

Jim Horn
Jim Horn asked
on
173 Views
Last Modified: 2014-08-07
Hi All

I'm building an SSIS package that consumes an XML file, then uses an XLST file to 'flatten' it into a single row.

Question:  How do I handle the elements not in the XLSD below?  Fuels-Unit,  All the Fuels-Costs values, and Dispatcher.

Here's the XML:
<FlightInfo>
    <FlightKey>
        <Alc>SCX</Alc>
        <Number>0117</Number>
        <STD>2014-06-30T11:00:00Z</STD>
        <OriginIcao>KMSP</OriginIcao>
    </FlightKey>
    <Compute Timestamp="2014-06-30 09:09:00">
        <Fuels Unit="LBS">
            <Pre>27151</Pre>
            <Release>10651</Release>
            <Tankerage>16500</Tankerage>
            <Burn>3830</Burn>
            <Arrival>22996</Arrival>
            <Costs>
                <Origin Currency="USD" Quantity="USG">3.11</Origin>
                <Destination Currency="USD" Quantity="USG">4.00</Destination>
                <Savings Currency="USD">2098.98</Savings>
            </Costs>
        </Fuels>
        <Dispatcher>NATHAN ROOD</Dispatcher>
    </Compute>
</FlightInfo>

Open in new window

Here's the XLSD, with the columns I was able to piece together..
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
   <xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/>
   
   <xsl:template match="/FlightInfo">
      <xsl:text>Alc,Number,STD,OriginIcao,Pre,Release,Tankerage,Burn,Fuel&#13;&#10;</xsl:text>
     
      <xsl:for-each select="FlightKey">
         <xsl:value-of select="Alc" /><xsl:text>","</xsl:text>
         <xsl:value-of select="Number" /><xsl:text>","</xsl:text>
         <xsl:value-of select="STD" /><xsl:text>","</xsl:text>
         <xsl:value-of select="OriginIcao" /><xsl:text>","</xsl:text>
      </xsl:for-each> 

      <xsl:for-each select="Compute/Fuels">
         <xsl:value-of select="Pre" /><xsl:text>","</xsl:text>
         <xsl:value-of select="Release" /><xsl:text>","</xsl:text>
         <xsl:value-of select="Tankerage" /><xsl:text>","</xsl:text>
         <xsl:value-of select="Burn" /><xsl:text>","</xsl:text>
         <xsl:value-of select="Arrival" /><xsl:text>","</xsl:text>
      </xsl:for-each> 
      
      <xsl:value-of select="/Compute/Dispatcher" /><xsl:text>","</xsl:text>
      
   </xsl:template>
</xsl:stylesheet> 

Open in new window

Thanks in advance.
Jim
Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Author

Commented:
Couple of follow-on questions...

What is a 'template'?
Is there any way to specify the data type of each column?
zc2
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Author

Commented:
Thanks much.  -Jim
zc2
CERTIFIED EXPERT

Commented:
You're welcome.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.