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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 2nd, 2017, 05:32 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2017
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Question Problems dealing with xml sporadic and repetitive tags using xsl

I have the following XML file I am converting to csv, the problem is, the first data section is all string tags which I can skip if I need and the second section is a mix of string and int tags. i am able to get the data out, but there is a weird block of data on top i am unable to remove. The XML file is automatically generated so I cant change it.

<?xml version="1.0" encoding="utf-8"?>
<methodResponse><params><param><value>
<struct>
<member><name>columns</name><value>
<array><data>
<value><string>id</string></value>
<value><string>scanTime</string></value>
<value><string>host</string></value>
<value><string>vuln</string></value>
<value><string>port</string></value>
<value><string>protocol</string></value>
</data></array>
</value></member>
<member><name>table</name><value>
<array><data>
<value>
<array><data>
<value><int>1</int></value>
<value><int>1414010812</int></value>
<value><string>Host.5</string></value>
<value><string>Vuln.6230</string></value>
<value><int>500</int></value>
<value><string>udp</string></value>
</data></array>
</value>
<value>
</data></array>
</value></member>
</struct></value>
</param>
</params>
</methodResponse>

my XSL 1.0 code below

<xsl:variable name="new-line" select="'
'"/>
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:template match="value/array/data">
<xsl:for-each select="//array/data">
<xsl:for-each select="value">
<xsl:value-of select="translate(*, $new-line,' ')"/>,
</xsl:for-each><br/>;
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

my desired output

id,scanTime,host,vuln,port,protocol
1,1414010812,Host.5,Vuln.6230,500,udp;
2,1414010978,Host.6,Vuln.1191,22,tcp;
3,1414010978,Host.6,Vuln.30535,22,tcp;
4,1414010978,Host.6,Vuln.78682,22,tcp;
5,1414010978,Host.6,Vuln.78683,22,tcp;

The problem is that it runs through the process and prints everything on one line with huge spaces before it prints my desired output.

I have read the best practices for posting, however this is my first post so feel free leave any solid feedback for posting etiquette. Thank you
Reply With Quote
  #2 (permalink)  
Old July 2nd, 2017, 05:52 PM
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

Firstly, I'd suggest that unless your question is specifically about the content of a Wrox/Wiley book, you're probably better off posting the question on StackOverflow these days. That's where you are most likely to get an answer.

Your code does

Code:
<xsl:template match="value/array/data">
  <xsl:for-each select="//array/data">
which means that whenever a data element is encountered, you are processing every data element in the whole document.

In addition, you're applying the default template rules to whitespace text nodes in the source, which causes the whitespace to be copied to the output.

You're also attempting to generate newlines by outputting a br element, but that only makes sense when generating HTML: the text output method will ignore empty elements, it won't translate them into newlines.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
Leothedog (July 2nd, 2017)
  #3 (permalink)  
Old July 2nd, 2017, 06:24 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2017
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Thank you

Thank you for the reply and good tips
Reply With Quote
Reply


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
Dealing with the presence of an XML tag rather tha Mike250 SQL Server 2005 1 June 6th, 2008 03:50 PM
repetitive xml - sorry, I'm new to this... JamesHurrell XSLT 4 March 12th, 2008 04:24 PM
XSL:FO Querying block id tags goldendase XSLT 4 September 20th, 2007 02:54 PM
XSL containing JSTL tags! techfreak123 XSLT 5 August 1st, 2006 09:50 PM
namespaces appearing in tags after XSL translation mphare XSLT 4 February 20th, 2006 02:49 PM



All times are GMT -4. The time now is 02:38 AM.


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