Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 9th, 2009, 10:03 AM
Registered User
 
Join Date: Dec 2009
Posts: 3
Thanks: 4
Thanked 0 Times in 0 Posts
Default Convert XML to CSV with XML field names as column headers?

Hi,

I need to transform an XML file to a CSV format with column headers. The problem is that I will not know what those column headers are so I would like to use the field name within the XML file as a default. This may sound a bit crazy but the consuming application maps the 'unknown' fields to known fields.

I found the following style sheet to perform the transform but I can't get the column headers dynamically:

Code:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="iso-8859-1"/>
<xsl:param name="fieldNames" select="'yes'" />
<xsl:strip-space elements="*" />
 <xsl:template match="/*/child::*">
<xsl:for-each select="child::*">
<xsl:if test="position() != last()">"<xsl:value-of select="normalize-space(.)"/>", </xsl:if>
<xsl:if test="position() = last()">"<xsl:value-of select="normalize-space(.)"/>"<xsl:text>&#xD;</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
My actual XML file is quite large so I have posted a smaller, representative sample below:

Code:
<?xml version="1.0" standalone="yes"?>
<ConfigOpt>
  <ConfigValues>
    <OptionName>BusinessName</OptionName>
    <OptionValue>SBD Manufacturing &amp; Distribution</OptionValue>
  </ConfigValues>
  <ConfigValues>
    <OptionName>ExportFile</OptionName>
    <OptionValue>C:\MaterialExport.csv</OptionValue>
  </ConfigValues>
  <ConfigValues>
    <OptionName>ExportFrequency</OptionName>
    <OptionValue>1</OptionValue>
  </ConfigValues>
  <ConfigValues>
    <OptionName>StandardMarkup</OptionName>
    <OptionValue>100</OptionValue>
  </ConfigValues>
  <ConfigValues>
    <OptionName>IncludeInactive</OptionName>
    <OptionValue>True</OptionValue>
  </ConfigValues>
  <ConfigValues>
    <OptionName>RetailRounding</OptionName>
    <OptionValue>True</OptionValue>
  </ConfigValues>
</ConfigOpt>
The desired output format would be as follows:

"OptionName", "OptionValue"
"BusinessName", "SBD Manufacturing & Distribution"
"ExportFile", "C:\MaterialExport.csv"
"ExportFrequency", "1"
"StandardMarkup", "100"
"IncludeInactive", "True"
"RetailRounding", "True"


Hopefully this can be accomplished and any help offered would be most appreciated.

Thanks,

Scott
  #2 (permalink)  
Old December 9th, 2009, 10:19 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,133
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Looks fine to me.

If you are producing a windows file you will need CR + LF to make the line break e.g. & #xD; & #xA; (no spaces).
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
  #3 (permalink)  
Old December 9th, 2009, 10:22 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,133
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Sorry, just realised what you meant.

Include the following at the top:

Code:
<xsl:template match="/">"<xsl:value-of select="name(*/*[1]/*[1])"/>","<xsl:value-of select="name(*/*[1]/*[2])"/>"<xsl:text>&#xD;</xsl:text>
       <xsl:apply-templates />
   </xsl:template>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
swheeler (December 9th, 2009)
  #4 (permalink)  
Old December 9th, 2009, 10:26 AM
mhkay's Avatar
Wrox Author
Points: 18,252, Level: 58
Points: 18,252, Level: 58 Points: 18,252, Level: 58 Points: 18,252, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,929
Thanks: 0
Thanked 281 Times in 276 Posts
Default

Add the template rule


<xsl:template match="/*">
<xsl:for-each select="*[1]/*">
<xsl:text>"</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>"</xsl:text>
<xsl:if test="position() != last()">, </xsl:if>
<xsl:if test="position() = last()">
<xsl:text>&#xD;</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:template>

Not tested.

Though like Sam, I would suggest using xA or XDxA for the newline.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
swheeler (December 9th, 2009)
  #5 (permalink)  
Old December 9th, 2009, 11:29 AM
Registered User
 
Join Date: Dec 2009
Posts: 3
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Sam & Michael,

Many thanks for the quick response.

Both pieces of code work; Sam's within the context of my example and Michael's in a more dynamic mode. My orignial post included and XML file that had two fields. It looks like Sam's code correctly accomodated a fixed number of fields while Michael's appears to have detected and transformed an unknown number of columns (which is the case with my input file).

Being new to XLST I noticed that my transform, using Xsl.XslCompiledTransform, did not 'flatten' completely the highly nested XML file that represents my actual data. Let me qualify this by saying that my XML test file has some redundant field names in different levels of the structure. For instance, 'ShipTo' and 'BillTo' addresses, while represented in different nodes, both have the components Address1, Address2, City, State, and Zip. I have no idea how this might be contributing to my 'jumbled' output.

I also noticed that some of my input records do not have complete information reresented, even if it is technically an empty string. For instance, the 'ShipTo' may print two address lines while the 'BillTo' may print only one. So, in order to get a perfectly flat, redundant XML to CSV transform, are the following rules in order:

1. Node content must be complete, for each node in the structure.
2. No extraneous commas or double-quote marks in ANY field

Thanks for your help!

Scott
  #6 (permalink)  
Old December 9th, 2009, 11:49 AM
mhkay's Avatar
Wrox Author
Points: 18,252, Level: 58
Points: 18,252, Level: 58 Points: 18,252, Level: 58 Points: 18,252, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,929
Thanks: 0
Thanked 281 Times in 276 Posts
Default

If your input XML is not a completely flat and regular rows-and-columns structure then you are going to have to explain much more carefully how you want it processed.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
swheeler (December 9th, 2009)
  #7 (permalink)  
Old August 6th, 2011, 12:53 PM
Registered User
 
Join Date: Aug 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mhkay View Post
If your input XML is not a completely flat and regular rows-and-columns structure then you are going to have to explain much more carefully how you want it processed.
I also have to transform a XML to CSV.My CSV needs to looke like that:

ReportHost,pluginID,solution,risk_factor
... ... ... ...

I am in a pickle so I will be gratefull for any kind of suggestions. pluginID is an attribute of the ReportItem element which is a chiled of the ReportHost element. I started writing the code to get the name of "Reporthost" but instead in the result was written everything that is inside the "Report" node.

This is the code I wrote. Please tell me where I am wrong??

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text"/>

<xsl:template match="/">
<xsl:apply-templates select="./Report/ReportHost"></xsl:apply-templates>
<xsl:value-of select="name(ReportHost)"/>
</xsl:template>

</xsl:stylesheet>

Here is the XML:

<NessusClientData_v2>
<Policy>
<policyName>all</policyName>
<policyComments></policyComments>
<Preferences>
<ServerPreferences>
<preference>
<name>max_simult_tcp_sessions</name>
<value>unlimited</value>
</preference>
</ServerPreferences>
<PluginsPreferences>
<item>
<pluginName>Hydra: PostgreSQL</pluginName>
<pluginId>18660</pluginId>
<fullName>Hydra: PostgreSQL[entry]:Database name (optional) :</fullName>
<preferenceName>Database name (optional) :</preferenceName>
<preferenceType>entry</preferenceType>
<preferenceValues></preferenceValues>
<selectedValue></selectedValue>
</item>
</PluginsPreferences>
</Preferences>
<FamilySelection>
<FamilyItem>
<FamilyName>MacOS X Local Security Checks</FamilyName>
<Status>enabled</Status>
</FamilyItem>
</FamilySelection>
</Policy>
<Report name="internal_all_nessus">
<ReportHost name="10.0.0.80">
<HostProperties>
<tag name="HOST_END">Tue Jun 28 14:25:11 2011</tag>
<tag name="mac-address">00:15:f9:f8:b0:27</tag>
<tag name="host-ip">10.0.0.80</tag>
<tag name="host-fqdn">SIP0015F9F8B027.lan</tag>
<tag name="HOST_START">Tue Jun 28 14:20:24 2011</tag>
</HostProperties>
<ReportItem port="23" svc_name="telnet" protocol="tcp" severity="0" pluginID="0" pluginName="" pluginFamily=""/>
<ReportItem port="5060" svc_name="sip" protocol="udp" severity="1" pluginID="21642" pluginName="Session Initiation Protocol Detection" pluginFamily="Service detection">
<solution>If possible, filter incoming connections to the port so that it is
used by trusted sources only.</solution><risk_factor>None</risk_factor><description>The remote system is running software that speaks the Session
Initiation Protocol.

SIP is a messaging protocol to initiate communication sessions between
systems. It is a protocol used mostly in IP Telephony networks /
systems to setup, control and teardown sessions between two or more
systems.</description><plugin_publication_date>2003/12/29</plugin_publication_date><synopsis>The remote system is a SIP signaling device.</synopsis><plugin_type>remote</plugin_type><see_also>http://en.wikipedia.org/wiki/Session_Initiation_Protocol</see_also><plugin_modification_date>2011/03/07</plugin_modification_date><plugin_output>
The remote service was identified as :

Cisco-CP7960G/8.0

It supports the following options :

ACK,BYE,CANCEL,INVITE,NOTIFY,OPTIONS,REFER,REGISTE R,UPDATE
</plugin_output>
<plugin_version>$Revision: 1.18 $</plugin_version></ReportItem>
</ReportHost>
</Report>
</NessusClientData_v2>
  #8 (permalink)  
Old August 7th, 2011, 07:51 AM
mhkay's Avatar
Wrox Author
Points: 18,252, Level: 58
Points: 18,252, Level: 58 Points: 18,252, Level: 58 Points: 18,252, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,929
Thanks: 0
Thanked 281 Times in 276 Posts
Default

It's really much better to start a new thread for a new question.

I don't know why you are doing name(ReportHost) as the name of the ReportHost element will always be "ReportHost", so this will output "ReportHost" if your document has ReportHost as its outermost element, and nothing otherwise (which is the case with your example XML).

Similarly it looks from your example as if <xsl:apply-templates select="./Report/ReportHost"> will select nothing and therefore output nothing. I would expect to see <xsl:apply-templates select="NessusClientData_v2/Report/ReportHost"/>. And then I would expect to see a template rule that processes the ReportHost elements.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
  #9 (permalink)  
Old August 7th, 2011, 06:49 PM
Registered User
 
Join Date: Aug 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot, I will try that out. Basically I need the csv to have the headers I mentioned in my previous reply (the names of the elements) and then their values.

If there are any suggestions I am all open :) I am new to XSL and it's not 100% clear to me yet how the templates apply to the document I process.

Thank you again for your time

M.T.

Last edited by mtsilik; August 7th, 2011 at 06:51 PM.
  #10 (permalink)  
Old February 10th, 2012, 09:29 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to convert a Complex XML to CSV File in .Net?

I Have a requierment of converting Complex XML Document to CSV File which should've specific format. I tried with many samples in .Net and tried to create XSL in many patterns but i couldn't get exact outpt i need. It would be much helpful if anyone can give me some sample XSL File by which i can achieve the desired output. Herewith i've attached sample XML and the XSL file i tried and finally the sample output file which i need.

Sample input XML File
Code:
<?xml version="1.0" encoding="UTF-8"?> <loggingpayload xmlns:e="http://schema.dadcdigital.com/dbb/data/2010/externaltask/logging" xmlns:t="http://schema.dadcdigital.com/dbb/data/2010/externaltask/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">   <t:duedate>12/22/2011 8:00:00 AM</t:duedate>   <e:workflowtype>Tape</e:workflowtype>   <e:title xmlns:a="http://schema.dadcdigital.com/dbb/data/2010/inventory/">     <a:guid>d572c250-b8a6-e011-88b0-e532a29f83eb</a:guid>     <a:displaycode>237557</a:displaycode>     <a:titlelevel>Episode</a:titlelevel>     <a:name>EPISODE #0406</a:name>     <a:seriesname>UGLY BETTY</a:seriesname>     <a:seasonname>SEASON 04</a:seasonname>     <a:episodenumber>0406</a:episodenumber>     <a:alphas>       <a:alpha>         <a:guid>2c7ec7d5-6ca7-e011-88b0-e532a29f83eb</a:guid>         <a:displaycode>410163</a:displaycode>         <a:externalalphakey>1100181</a:externalalphakey>         <a:name>Negative</a:name>         <a:components>           <a:component type="Audio Track">             <a:guid>8ccf3c1b-e3c1-4ee1-8fca-6b55ed3276e8</a:guid>             <a:displaycode>129183</a:displaycode>             <a:componentstatus>Validation</a:componentstatus>             <a:tapebarcode></a:tapebarcode>             <a:componentgroupassociations>               <a:componentgroupassociation>                 <a:componentgroup>                   <a:type>KitContentGroup</a:type>                   <a:guid>9fd12a60-5527-e111-b38e-00155d0a22a0</a:guid>                   <a:displaycode>123884</a:displaycode>                 </a:componentgroup>                 <a:offset>0</a:offset>               </a:componentgroupassociation>             </a:componentgroupassociations>             <a:audioconfiguration>5.1</a:audioconfiguration>             <a:audiocontent></a:audiocontent>             <a:language></a:language>             <a:audiomix></a:audiomix>             <a:runtime></a:runtime>             <a:audiocodec>PCM</a:audiocodec>             <a:audiocontainer>MXF</a:audiocontainer>             <a:sampleratehz>48000Hz</a:sampleratehz>             <a:bitspersample>24</a:bitspersample>             <a:audiobitratekbps>1125</a:audiobitratekbps>             <a:isconstantbitrate>True</a:isconstantbitrate>             <a:minimumbitratekbps></a:minimumbitratekbps>             <a:maximumbitratekbps></a:maximumbitratekbps>             <a:audiochannelcomponents>               <a:audiochannelcomponent>                 <a:guid>533752b4-2ec2-492c-a0f4-180f31736989</a:guid>                 <a:displaycode>129186</a:displaycode>                 <a:componentstatus>Validation</a:componentstatus>                 <a:filedescriptors>                   <a:filedescriptor>                     <a:guid>2b2cf10d-5b27-e111-b38e-00155d0a22a0</a:guid>                     <a:encodingequipment></a:encodingequipment>                     <a:encodingprofile></a:encodingprofile>                     <a:checksumvalue></a:checksumvalue>                     <a:checksumtype></a:checksumtype>                     <a:fileformat>audio/wav;.wav</a:fileformat>                     <a:encodedate></a:encodedate>                   </a:filedescriptor>                 </a:filedescriptors>                 <a:audiochannelinfile>1</a:audiochannelinfile>                 <a:audiochannelontape></a:audiochannelontape>                 <a:audiostreaminfile>1</a:audiostreaminfile>                 <a:audiochannelassignment>Rear Left</a:audiochannelassignment>               </a:audiochannelcomponent>               <a:audiochannelcomponent>                 <a:guid>33a98bbc-e973-45aa-996b-8098e5dc4ef0</a:guid>                 <a:displaycode>129187</a:displaycode>                 <a:componentstatus>Validation</a:componentstatus>                 <a:filedescriptors>                   <a:filedescriptor>                     <a:guid>2e2cf10d-5b27-e111-b38e-00155d0a22a0</a:guid>                     <a:encodingequipment></a:encodingequipment>                     <a:encodingprofile></a:encodingprofile>                     <a:checksumvalue></a:checksumvalue>                     <a:checksumtype></a:checksumtype>                     <a:fileformat>audio/wav;.wav</a:fileformat>                     <a:encodedate></a:encodedate>                   </a:filedescriptor>                 </a:filedescriptors>                 <a:audiochannelinfile>1</a:audiochannelinfile>                 <a:audiochannelontape></a:audiochannelontape>                 <a:audiostreaminfile>1</a:audiostreaminfile>                 <a:audiochannelassignment>Rear Right</a:audiochannelassignment>               </a:audiochannelcomponent>               <a:audiochannelcomponent>                 <a:guid>a641195e-b8c2-4b22-b0db-8b78d6b3bd4f</a:guid>                 <a:displaycode>129188</a:displaycode>                 <a:componentstatus>Validation</a:componentstatus>                 <a:filedescriptors>                   <a:filedescriptor>                     <a:guid>52ba6307-5b27-e111-b38e-00155d0a22a0</a:guid>                     <a:encodingequipment></a:encodingequipment>                     <a:encodingprofile></a:encodingprofile>                     <a:checksumvalue></a:checksumvalue>                     <a:checksumtype></a:checksumtype>                     <a:fileformat>audio/wav;.wav</a:fileformat>                     <a:encodedate></a:encodedate>                   </a:filedescriptor>                 </a:filedescriptors>                 <a:audiochannelinfile>1</a:audiochannelinfile>                 <a:audiochannelontape></a:audiochannelontape>                 <a:audiostreaminfile>1</a:audiostreaminfile>                 <a:audiochannelassignment>LFE</a:audiochannelassignment>               </a:audiochannelcomponent>               <a:audiochannelcomponent>                 <a:guid>5a151669-7731-4ef7-87b3-8e77a32acae1</a:guid>                 <a:displaycode>129189</a:displaycode>                 <a:componentstatus>Validation</a:componentstatus>                 <a:filedescriptors>                   <a:filedescriptor>                     <a:guid>4fba6307-5b27-e111-b38e-00155d0a22a0</a:guid>                     <a:encodingequipment></a:encodingequipment>                     <a:encodingprofile></a:encodingprofile>                     <a:checksumvalue></a:checksumvalue>                     <a:checksumtype></a:checksumtype>                     <a:fileformat>audio/wav;.wav</a:fileformat>                     <a:encodedate></a:encodedate>                   </a:filedescriptor>                 </a:filedescriptors>                 <a:audiochannelinfile>1</a:audiochannelinfile>                 <a:audiochannelontape></a:audiochannelontape>                 <a:audiostreaminfile>1</a:audiostreaminfile>                 <a:audiochannelassignment>Front Center</a:audiochannelassignment>               </a:audiochannelcomponent>               <a:audiochannelcomponent>                 <a:guid>65476bb6-e997-494e-ace5-bbd1880732a6</a:guid>                 <a:displaycode>129190</a:displaycode>                 <a:componentstatus>Validation</a:componentstatus>                 <a:filedescriptors>                   <a:filedescriptor>                     <a:guid>4cba6307-5b27-e111-b38e-00155d0a22a0</a:guid>                     <a:encodingequipment></a:encodingequipment>                     <a:encodingprofile></a:encodingprofile>                     <a:checksumvalue></a:checksumvalue>                     <a:checksumtype></a:checksumtype>                     <a:fileformat>audio/wav;.wav</a:fileformat>                     <a:encodedate></a:encodedate>                   </a:filedescriptor>                 </a:filedescriptors>                 <a:audiochannelinfile>1</a:audiochannelinfile>                 <a:audiochannelontape></a:audiochannelontape>                 <a:audiostreaminfile>1</a:audiostreaminfile>                 <a:audiochannelassignment>Right</a:audiochannelassignment>               </a:audiochannelcomponent>               <a:audiochannelcomponent>                 <a:guid>0d7021a9-151f-425b-b02f-daf65ed72874</a:guid>                 <a:displaycode>129191</a:displaycode>                 <a:componentstatus>Validation</a:componentstatus>                 <a:filedescriptors>                   <a:filedescriptor>                     <a:guid>3c5742fc-5a27-e111-b38e-00155d0a22a0</a:guid>                     <a:encodingequipment></a:encodingequipment>                     <a:encodingprofile></a:encodingprofile>                     <a:checksumvalue></a:checksumvalue>                     <a:checksumtype></a:checksumtype>                     <a:fileformat>audio/wav;.wav</a:fileformat>                     <a:encodedate></a:encodedate>                   </a:filedescriptor>                 </a:filedescriptors>                 <a:audiochannelinfile>1</a:audiochannelinfile>                 <a:audiochannelontape></a:audiochannelontape>                 <a:audiostreaminfile>1</a:audiostreaminfile>                 <a:audiochannelassignment>Left</a:audiochannelassignment>               </a:audiochannelcomponent>             </a:audiochannelcomponents>           </a:component>         </a:components>       </a:alpha>     </a:alphas>   </e:title> </loggingpayload>
Sample XSL File
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"                 xmlns:t="http://schema.dadcdigital.com/dbb/data/2010/externaltask/"                 xmlns:e="http://schema.dadcdigital.com/dbb/data/2010/externaltask/logging"                 xmlns:a="http://schema.dadcdigital.com/dbb/data/2010/inventory/">   <xsl:output method="text" encoding="iso-8859-1"/>   <!--<xsl:preserve-space elements="*" />-->   <!--<xsl:template match="loggingpayload">     <xsl:apply-templates select="e:title"/>     <xsl:apply-templates select="a:alphas"/>   </xsl:template>-->    <xsl:template match="/">     <xsl:apply-templates select="loggingpayload/e:title"/>   </xsl:template>    <xsl:template match="e:title">     <xsl:value-of select="name()"/>     <!--<xsl:apply-templates select="output[contains(text(), '.com')]"/>     <xsl:apply-templates select="input[contains(text(), '.com')]"/>-->     <xsl:text>&#x0a;</xsl:text>   </xsl:template>    <!--<xsl:template match="output|input">     <xsl:text>, </xsl:text>     <xsl:value-of select="text()"/>     <xsl:if test="@ confirmed='no'">       <xsl:text> *</xsl:text>     </xsl:if>   </xsl:template>-->    <!--<xsl:template match="e:title">     <xsl:for-each select="*">        -->   <!--It can't be used as the name element has Prefix       <xsl:value-of select="name()"/>-->   <!--        -->   <!--First break line when it reachhes to Alpas-->   <!--         -->   <!--<xsl:value-of select="name()"/>-->   <!--       <xsl:value-of select="node()"/>       <xsl:if test="position( ) != last( )">         <xsl:value-of select="','"/>       </xsl:if>        <xsl:if test="*">         <xsl:text>Text Alpha</xsl:text>          -->   <!--For Alphas-->   <!--         <xsl:for-each select="*">           <xsl:value-of select="."/>           <xsl:if test="position( ) != last( )">             <xsl:value-of select="','"/>           </xsl:if>         </xsl:for-each>        </xsl:if>     </xsl:for-each>     <xsl:text>
</xsl:text>   </xsl:template>-->      <!--<xsl:for-each select="loggingpayload">       -->   <!--<xsl:text>Metadata CSV</xsl:text>       <xsl:text>   </xsl:text>-->   <!--        -->   <!--<xsl:value-of select="name(.)"/>-->   <!--       <xsl:text>Due date</xsl:text>       <xsl:value-of select="t:duedate"/>       <xsl:text>   </xsl:text>        <xsl:text>Workflow Type</xsl:text>       <xsl:value-of select="e:workflowtype"/>       <xsl:text>   </xsl:text>       -->   <!--<xsl:if test="position() = first()">         <fo:block linefeed-treatment="preserve">         </fo:block>       </xsl:if>-->   <!--        <xsl:for-each select="e:title">         <xsl:text>Title:</xsl:text>         <xsl:value-of select="a:name"/>         <xsl:text>   </xsl:text>          <xsl:text>Title ID:</xsl:text>         <xsl:value-of select="a:guid"/>         <xsl:text>   </xsl:text>          <xsl:text>Display code:</xsl:text>         <xsl:value-of select="a:displaycode"/>         <xsl:text>   </xsl:text>          <xsl:text>Title level:</xsl:text>         <xsl:value-of select="a:titlelevel"/>         <xsl:text>   </xsl:text>          <xsl:text>Seriesname:</xsl:text>         <xsl:value-of select="a:seriesname"/>         <xsl:text>   </xsl:text>          <xsl:text>Season name:</xsl:text>         <xsl:value-of select="a:seasonname"/>         <xsl:text>   </xsl:text>          <xsl:text>Episode number:</xsl:text>         <xsl:value-of select="a:episodenumber"/>         <xsl:text>   </xsl:text>          <xsl:text>Display code:</xsl:text>         <xsl:value-of select="a:displaycode"/>         <xsl:text>   </xsl:text>       </xsl:for-each>        <xsl:for-each select="e:title/a:alphas/a:alpha">         <xsl:text>Alpha:</xsl:text>         <xsl:value-of select="a:name"/>         <xsl:text>   </xsl:text>          <xsl:text>Alpha ID:</xsl:text>         <xsl:value-of select="a:guid"/>         <xsl:text>   </xsl:text>          <xsl:text>Display code:</xsl:text>         <xsl:value-of select="a:displaycode"/>         <xsl:text>   </xsl:text>          <xsl:text>External alpha key:</xsl:text>         <xsl:value-of select="a:externalalphakey"/>         <xsl:text>   </xsl:text>       </xsl:for-each>        <xsl:for-each select="e:title/a:alphas/a:alpha/a:components/a:component">         <xsl:text>Component type:</xsl:text>         <xsl:value-of select="@type"/>         <xsl:text>   </xsl:text>          <xsl:text>Component ID:</xsl:text>         <xsl:value-of select="a:guid"/>         <xsl:text>   </xsl:text>          <xsl:text>Display code:</xsl:text>         <xsl:value-of select="a:displaycode"/>         <xsl:text>   </xsl:text>          <xsl:text>Component status:</xsl:text>         <xsl:value-of select="a:componentstatus"/>         <xsl:text>   </xsl:text>          <xsl:text>Tape barcode:</xsl:text>         <xsl:value-of select="a:tapebarcode"/>         <xsl:text>   </xsl:text>          <xsl:text>Audio configuration:</xsl:text>         <xsl:value-of select="a:audioconfiguration"/>         <xsl:text>   </xsl:text>          <xsl:text>Audio content:</xsl:text>         <xsl:value-of select="a:audiocontent"/>         <xsl:text>   </xsl:text>          <xsl:text>Language:</xsl:text>         <xsl:value-of select="a:language"/>         <xsl:text>   </xsl:text>          <xsl:text>Audiomix:</xsl:text>         <xsl:value-of select="a:audiomix"/>         <xsl:text>   </xsl:text>          <xsl:text>Runtime:</xsl:text>         <xsl:value-of select="a:runtime"/>         <xsl:text>   </xsl:text>          <xsl:text>Audio codec:</xsl:text>         <xsl:value-of select="a:audiocodec"/>         <xsl:text>   </xsl:text>          <xsl:text>Audio container:</xsl:text>         <xsl:value-of select="a:audiocontainer"/>         <xsl:text>   </xsl:text>          <xsl:text>Sampleratehz:</xsl:text>         <xsl:value-of select="a:sampleratehz"/>         <xsl:text>   </xsl:text>          <xsl:text>Bitspersample:</xsl:text>         <xsl:value-of select="a:bitspersample"/>         <xsl:text>   </xsl:text>          <xsl:text>Audio bitrate kbps:</xsl:text>         <xsl:value-of select="a:audiobitratekbps"/>         <xsl:text>   </xsl:text>          <xsl:text>Isconstantbitrate:</xsl:text>         <xsl:value-of select="a:isconstantbitrate"/>         <xsl:text>   </xsl:text>          <xsl:text>Minimum bitrate kbps:</xsl:text>         <xsl:value-of select="a:minimumbitratekbps"/>         <xsl:text>   </xsl:text>          <xsl:text>Maximum bitrate kbps:</xsl:text>         <xsl:value-of select="a:maximumbitratekbps"/>         <xsl:text>   </xsl:text>        </xsl:for-each>        <xsl:for-each select="e:title/a:alphas/a:alpha/a:components/a:component/a:componentgroupassociations/a:componentgroupassociation/a:componentgroup">         <xsl:text>Component group type:</xsl:text>         <xsl:value-of select="a:type"/>         <xsl:text>   </xsl:text>          <xsl:text>group id:</xsl:text>         <xsl:value-of select="a:guid"/>         <xsl:text>   </xsl:text>          <xsl:text>Display code:</xsl:text>         <xsl:value-of select="a:displaycode"/>         <xsl:text>   </xsl:text>        </xsl:for-each>        <xsl:for-each select="e:title/a:alphas/a:alpha/a:components/a:component/a:audiochannelcomponents/a:audiochannelcomponent">                  <xsl:text>Audio channel component id:</xsl:text>         <xsl:value-of select="a:guid"/>         <xsl:text>   </xsl:text>          <xsl:text>Display code:</xsl:text>         <xsl:value-of select="a:displaycode"/>         <xsl:text>   </xsl:text>          <xsl:text>Status:</xsl:text>         <xsl:value-of select="a:componentstatus"/>         <xsl:text>   </xsl:text>          <xsl:text>Audio channel in file: </xsl:text>         <xsl:value-of select="a:audiochannelinfile"/>         <xsl:text>   </xsl:text>          <xsl:text>Audio channel on tape:</xsl:text>         <xsl:value-of select="a:audiochannelontape"/>         <xsl:text>   </xsl:text>          <xsl:text>Audio stream in file: </xsl:text>         <xsl:value-of select="a:audiostreaminfile"/>         <xsl:text>   </xsl:text>          <xsl:text>Audio channel assignment:</xsl:text>         <xsl:value-of select="a:audiochannelassignment"/>         <xsl:text>   </xsl:text>          <xsl:text>File descriptor ID:</xsl:text>         <xsl:value-of select="a:filedescriptors/a:filedescriptor/a:guid"/>         <xsl:text>   </xsl:text>          <xsl:text>Encoding equipment:</xsl:text>         <xsl:value-of select="a:filedescriptors/a:filedescriptor/a:encodingquipment"/>         <xsl:text>   </xsl:text>         <xsl:text>group id:</xsl:text>         <xsl:value-of select="a:guid"/>         <xsl:text>   </xsl:text>          <xsl:text>Encoding profile:</xsl:text>         <xsl:value-of select="a:filedescriptors/a:filedescriptor/a:encodingprofile"/>         <xsl:text>   </xsl:text>          <xsl:text>Checksum value:</xsl:text>         <xsl:value-of select="a:filedescriptors/a:filedescriptor/a:checksumvalue"/>         <xsl:text>   </xsl:text>          <xsl:text>Checksum type:</xsl:text>         <xsl:value-of select="a:filedescriptors/a:filedescriptor/a:checksumtype"/>         <xsl:text>   </xsl:text>          <xsl:text>File format:</xsl:text>         <xsl:value-of select="a:filedescriptors/a:filedescriptor/a:fileformat"/>         <xsl:text>   </xsl:text>          <xsl:text>Encode date:</xsl:text>         <xsl:value-of select="a:filedescriptors/a:filedescriptor/a:encodedate"/>         <xsl:text>   </xsl:text>       </xsl:for-each>       -->   <!--<xsl:if test="position() != last()">         <xsl:value-of select="normalize-space(.)"/>         <xsl:text>&#xD;</xsl:text>       </xsl:if>       <xsl:if test="position()  = last()">         <xsl:value-of select="normalize-space(.)"/>         <xsl:text>&#xD;</xsl:text>       </xsl:if>-->   <!--     </xsl:for-each>   </xsl:template>--> </xsl:stylesheet>
Finally the output csv file should look like the following when opened in any text pad
Code:
Due date,Workflow type,,,,,,,,,,,,,,,, 1/25/2012 6:30:00 PM,Tape,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,, Title,Guid,Display code,Title level,Series name,Season name,Episode number,,,,,,,,,,, FATHER IS A BACHELOR,3c93ce83-86a6-e011-88b0-e532a29f83eb,153838,NonEpisodic,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,, Alpha Name,Guid,Display code,External alpha key,,,,,,,,,,,,,, TH,56d1b093-54a7-e011-88b0-e532a29f83eb,293075,964992,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,, Component type,Guid,Display code,Component status,Tape barcode,Audio configuration,audio content,Language,Audiomix,Runtime,Audio codec,Audio container,Sampleratehz,Bitspersample,Audio bitratekbps,Isconstantbitrate,Minimum bitratekbps,Maximum bitratekbps Audio Track,a9ea97bf-5ce9-4a0d-ad13-26fdeedf24cc,149371,Validation,,LT/RT,Composite,French - Continental,,0:0,PCM,MXF,48000Hz,24,1125,True,0,0 ,,,,,,,,,,,,,,,,, Component group type,Guid,Displaycode,Offset,,,,,,,,,,,,,, KitContentGroup,db8d8548-8442-e111-8089-00155d0a22a0,132168,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,, Audio Channel Components,,,,,,,,,,,,,,,,, ,Guid,Displaycode,Component status,Audio channel in file,Audio channel on tape,Audio stream in file,Audio channel assignment,File descriptor guid,Encoding equipment,Encoding profile,Checksum value,Checksum type,File format,Encode date,,, ,d79b9897-eaa3-4c6d-8a85-23ce2d52e52f,149372,Validation,1,,1,Left Total,b918d9d4-8542-e111-8089-00155d0a22a0,,,,,audio/wav;.wav,,,, ,0dd87a02-3182-4fa0-9f1c-d16fddf23020,149373,Validation,1,,1,Right Total,bf18d9d4-8542-e111-8089-00155d0a22a0,,,,,audio/wav;.wav,,,,
Closed Thread


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert 1 big XML to multiple smaller XML victorcorey XSLT 1 March 20th, 2008 05:59 AM
Convert XML to XML template question bonekrusher XSLT 3 July 12th, 2007 07:47 AM
convert XML to XMl - Another Namespace question bonekrusher XSLT 2 July 10th, 2007 07:32 AM
xml and news headers cynic_shankar XML 2 June 18th, 2005 10:51 AM
convert xml to csv woofy77 XSLT 0 December 8th, 2003 01:05 AM



All times are GMT -4. The time now is 10:14 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.