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 July 28th, 2014, 11:00 AM
Registered User
 
Join Date: Sep 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML to XML

I am having trouble getting xml tags to output. I am using this site to process.
http://xslt.online-toolz.com/tools/x...sformation.php

XML:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<?xml-stylesheet type="text/xsl" href="xsl.xsl"?>
<Root>
	<Row>
		<Number>1</Number>
		<SKU>3225A</SKU>
		<COST>1.98</COST>
	</Row>
	<Row>
		<Number>2</Number>
		<SKU>MN145</SKU>
		<COST>1.82</COST>
	</Row>
	<Row>
		<Number>3</Number>
		<SKU>MN143</SKU>
		<COST>1.82</COST>
	</Row>
</Root>
XSLT:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<xsl:for-each select="Root/Row">
<header>
<xsl:value-of select="SKU"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Output:
Quote:
Error:XSLTProcessor::transformToXml() [<a href='xsltprocessor.transformtoxml'>xsltprocessor. transformtoxml</a>]: No stylesheet associated to this object
Output I want:
<header>
1
3225A
1.98

...etc.

It seems the <header> tag is breaking it saying No stylesheet associated to this object.

I just want to rebuild an xml document changing the SKU on every iteration.

I have tried the disable-output-escaping="yes" to no avail. It seems it doesn't want to output the <header> tag as is that I need.

What am I doing wrong?
thanks
 
Old July 28th, 2014, 03:54 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's a weird error message, but your stylesheet is wrong. An XSLT stylesheet must be a well-formed XML document, so an unmatched &lt;header&gt; start tag is not allowed.

Your desired output is also not well-formed XML. You can produce that output if you want, but you will need to use the text output method rather than the XML output method.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old July 28th, 2014, 04:09 PM
Registered User
 
Join Date: Sep 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out. I see you need opening and closing tags for it to work.


XML...
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<?xml-stylesheet type="text/xsl" href="xsl.xsl"?>
<Root>
	<Row>
		<Number>1</Number>
		<SKU>3225A</SKU>
		<COST>1.98</COST>
	</Row>
	<Row>
		<Number>2</Number>
		<SKU>MN145</SKU>
		<COST>1.82</COST>
	</Row>
	<Row>
		<Number>3</Number>
		<SKU>MN143</SKU>
		<COST>1.82</COST>
	</Row>
</Root>

XSLT...
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
  
      <xsl:for-each select="Root/Row">
<Message>
<MessageID><xsl:value-of select="Number"/></MessageID><OperationType>Update</OperationType>
<Override><SKU><xsl:value-of select="SKU"/></SKU>
<ShippingOverride><ShipOption>Std Cont US Street Addr</ShipOption><Type>Exclusive</Type><ShipAmount currency="USD"><xsl:value-of select="COST"/></ShipAmount></ShippingOverride>
</Override>
</Message>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Output...
<?xml version="1.0" encoding="utf-8"?>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Override>
<SKU>3225A</SKU>
<ShippingOverride>
<ShipOption>Std Cont US Street Addr</ShipOption>
<Type>Exclusive</Type>
<ShipAmount currency="USD">1.98</ShipAmount>
</ShippingOverride>
</Override>
</Message><Message>
<MessageID>2</MessageID>
<OperationType>Update</OperationType>
<Override>
<SKU>MN145</SKU>
<ShippingOverride>
<ShipOption>Std Cont US Street Addr</ShipOption>
<Type>Exclusive</Type>
<ShipAmount currency="USD">1.82</ShipAmount>
</ShippingOverride>
</Override>
</Message><Message>
<MessageID>3</MessageID>
<OperationType>Update</OperationType>
<Override>
<SKU>MN143</SKU>
<ShippingOverride>
<ShipOption>Std Cont US Street Addr</ShipOption>
<Type>Exclusive</Type>
<ShipAmount currency="USD">1.82</ShipAmount>
</ShippingOverride>
</Override>
</Message>

thanks for your help.
Do you recommend any processors online that may be better than the one I used? http://xslt.online-toolz.com/tools/x...sformation.php

Or is this one okay?

thanks!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert XML to CSV with XML field names as column headers? swheeler XSLT 10 February 10th, 2012 11:18 AM
How to post a XML file to a remote server and get a XML response back surendran ASP.NET 3.5 Professionals 2 January 29th, 2010 03:39 AM
Split xml file with result document and javax.xml.transform.Transformer. nisargmca XSLT 3 January 12th, 2010 06:26 AM
SQL Server 2005 XML: FOR XML PATH -> cdata? stoves SQL Server 2005 1 July 8th, 2008 02:40 AM
VB.net, adding XML data to an existing XML file saikoboarder XML 11 April 17th, 2008 04:19 PM





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