Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2008, 11:41 AM
Authorized User
 
Join Date: Mar 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default I'm a newb.... I think I'm doing something wrong..

I'm trying to use an XSL stylesheet to transform some XML data that came from a form. The application that exported the form data to xml has set up its elements with a character that I can't identify or a line break. Either way I can't seem to reference any of the elements through XPath because of this.

The document basically looks like this:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<form1
><elementNumber1
/><elementNumber2
>choose</elementNumber2
><element3
/>
</form1
>
can someone help! tell me what I'm not getting here... lol
 
Old March 18th, 2008, 11:46 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

What you have posted is not well-formed XML as the root element name in the start tag is 'form1' but the end tag has just 'form'.
You can't process mal-formed XML.

 
Old March 18th, 2008, 11:50 AM
Authorized User
 
Join Date: Mar 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ooops! you are correct buddy. thanks for pointing out the obvious. I just typed that in 2 seconds without care. But its fixed now and maybe you can focus on the problem at hand ....thanks...

 
Old March 18th, 2008, 11:52 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There's nothing wrong with having a newline in a start or end tag after the element name - it might seem badly formatted, but it's legal.

If it's some character that the XML parser is rejecting then you need to find out what character it is - look at the document in a hex editor.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 18th, 2008, 11:55 AM
Authorized User
 
Join Date: Mar 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I know that its legal, I'm not questioning the legality of the document or the fact that its well formed. I think your idea of a hex editor has helped me ...The xml parser isn't rejecting it, I just can't reference any of the element names directly in my XSL and I don't know if thats due to a unknown character or a line break in the element names. I was kind of hoping someone on here would have seen this exact style of xml formatting in thier previous experiences and would be able to identify it.
 
Old March 18th, 2008, 11:59 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I am not sure how we can help further, the posted snippet is now well-formed after the correction. The web forum however does not allow us the check the characters in your file, you would need to upload that file somewhere to a web server and post the URL to allow others to check the XML.
You could also load the XML document in a browser like Internet Explorer or Firefox, they will parse the XML and should give you an indication about wrong characters.

 
Old March 18th, 2008, 12:01 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If the document is being parsed OK then the odd formatting isn't the source of your problems. Show us the XPath expression that's giving unexpected results.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 18th, 2008, 12:13 PM
Authorized User
 
Join Date: Mar 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<xsl:template match="/form1">

 - doesn't recognize it.

so I guess now I am supposed to think that there is a character after the 1 thats is being displayed in the xml code as a line break? I'm going to put the file up and post a url in my next posting as sugguested....
 
Old March 18th, 2008, 12:34 PM
Authorized User
 
Join Date: Mar 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the actual document I'm trying to transform....

http://www.geocities.com/aem80211/jss.xml


I really appreciate everyone1 here taking the time to help a newb....

 
Old March 18th, 2008, 12:48 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I can process that XML document just fine, here is an XSLT 1.0 stylesheet that I run with Saxon 6.5:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:output method="text"/>

  <xsl:template match="/form1">
    <xsl:for-each select="*[normalize-space()]">
      <xsl:value-of select="concat('&quot;', name(), '&quot;: ', ., '#10;')"/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>
Result:
Code:
"SchoolState": CO
"P1Grade": ?
"P1Shirt": ?
"P1Gender": ?
"P1Ethnicity": Choose
"P2Grade": ?
"P2Shirt": ?
"P2Gender": ?
"P2Ethnicity": Choose
"P3Grade": ?
"P3Shirt": ?
"P3Gender": ?
"P3Ethnicity": Choose
"P4Grade": ?
"P4Shirt": ?
"P4Gender": ?
"P4Ethnicity": Choose
"CoachShirt": ?
"CoachGender": ?
"CoachEthnicity": Choose
So those element names do not have any strange characters in them.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Another newb syntax question mean34dean Access VBA 4 April 4th, 2008 07:45 AM
NEWB HERE Romaunt V. C# 8 August 16th, 2007 11:52 AM
Newb question zenobr BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 November 15th, 2006 10:19 PM
XSLT Newb. TimJR88 XSLT 1 November 21st, 2005 03:14 PM
Need Help (Newb at HTML) Therum HTML Code Clinic 1 January 31st, 2005 07:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.