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 May 4th, 2006, 10:05 AM
Authorized User
 
Join Date: Apr 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL help

Hi,

I posted earlier about an xsl document help with a similar xml doc and got perfect help. However, I don't know what I am doing wrong with this one...

I'm been having trouble with this xsl for the folllowing xml document. It is well formed, however, when you run it, none of the values for UIC, Name or Type appear in the results, just their blank elements. The reason I need this xsl transform is bc the xml is received from a webservice and it skips blank elements (meaning first row can have 3 elements, but if row two has an element that does not have data, it write 2 elements for that row).

At any rate, I need the actual data along with the elements to show up. If anyone can help me out with this I would GREATLY appreciate it.


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:vb="urn:ShipSchedules">
<xsl:template match="ArrayOfUnitType">

<UnitType>
    <UIC><xsl:value-of select="vb:UIC"/></UIC>
    <Name><xsl:value-of select="vb:Name"/></Name>
    <Type><xsl:value-of select="vb:Type"/></Type>

</UnitType>
</xsl:template>
</xsl:stylesheet>

-----------------------------------

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfUnitType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlsns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<?xml-stylesheet type="text/xsl" href="UnitType.xsl"?>
<UnitType>
    <UIC xmlns="urn:ShipSchedules">C2000</UIC>
    <Name xmlns="urn:ShipSchedules">N33</Name>
    <Type xmlns="urn:ShipSchedules">type1</Type>
</UnitType>
<UnitType>
    <UIC xmlns="urn:ShipSchedules">C2001</UIC>
    <Type xmlns="urn:ShipSchedules">type2</Type>
</UnitType>

</ArrayOfUnitType>
 
Old May 4th, 2006, 10:42 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

ArrayOfUnitType does not have a UIC child. You need

<xsl:value-of select="UnitType/vb:UIC"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 4th, 2006, 10:49 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Note (advertisement): if you were using schema-aware stylesheets, this error would have been detected by the compiler. See http://www.stylusstudio.com/schema_aware.html

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 4th, 2006, 11:23 AM
Authorized User
 
Join Date: Apr 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mhkay,

Thanks again for your quick response! I added your XPath addition, but now my problem is that it 1) The new xml results does not print out the ArrayOfUnitType root node and 2) only prints out the first instance of UnitType and it's children, ignoring every other instance of UnitType. My XPath is rusty...can you use a for each for this?

Here is my current xsl code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:vb="urn:ShipSchedules">
<xsl:template match="ArrayOfUnitType">

<UnitType>
    <UIC><xsl:value-of select="UnitType/vb:UIC"/></UIC>
    <Name><xsl:value-of select="UnitType/vb:Name"/></Name>
    <Type><xsl:value-of select="UnitType/vb:Type"/></Type>

</UnitType>
</xsl:template>
</xsl:stylesheet>
-------------------------

And, results:

<UnitType>
    <UIC xmlns="urn:ShipSchedules">C2000</UIC>
    <Name xmlns="urn:ShipSchedules">N33</Name>
    <Type xmlns="urn:ShipSchedules">type1</Type>
</UnitType>
------------------

When I want:

<ArrayOfUnitType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlsns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UnitType>
    <UIC xmlns="urn:ShipSchedules">C2000</UIC>
    <Name xmlns="urn:ShipSchedules">N33</Name>
    <Type xmlns="urn:ShipSchedules">type1</Type>
</UnitType>
<UnitType>
    <UIC xmlns="urn:ShipSchedules">C2001</UIC>
    <Name xmlns="urn:ShipSchedules"></Name>
    <Type xmlns="urn:ShipSchedules">type2</Type>

</UnitType>

</ArrayOfUnitType>


Thanks again for your help! :) (btw, I do have Stylus Studio, just not on this work computer. ;) )
 
Old May 4th, 2006, 11:35 AM
Authorized User
 
Join Date: Apr 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nevermind! I fixed it like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:vb="urn:ShipSchedules">
<xsl:template match="ArrayOfUnitType">
<ArrayOfUnitType>
<xsl:for-each select="UnitType">
  <UnitType>
    <UIC><xsl:value-of select="vb:UIC"/></UIC>
    <Name><xsl:value-of select="vb:Name"/></Name>
    <Type><xsl:value-of select="vb:Type"/></Type>

  </UnitType>
</xsl:for-each>
</ArrayOfUnitType>
</xsl:template>
</xsl:stylesheet>


 
Old May 4th, 2006, 11:44 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I wasn't trying to give you a complete stylesheet, only to solve the specific problem you asked for help with. Obviously your stylesheet isn't going to output an <ArrayOfUnitType> element unless you ask it to.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
differnce between xsl:apply-templates and xsl:call chandu.mca007 XSLT 2 June 12th, 2007 04:12 AM
xsl advise needed - Replacing UID through XSL Billyl XSLT 6 February 28th, 2006 05:46 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





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