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 January 28th, 2010, 01:19 PM
Authorized User
 
Join Date: Jan 2010
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So does it have to do with the tool that I am using to transform?
 
Old January 28th, 2010, 01:20 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

That second document has a namespace - the xmlns="http://www.xxx.com" is its namespace. You'll need to define that in the XSLT file and use it as Martin illustrated above.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old January 28th, 2010, 01:32 PM
Authorized User
 
Join Date: Jan 2010
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Sam,

I modified, Still did not work. See below for the latest version I have:


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

<xsl:output encoding="UTF-8" method="xml"/>
<xsl:param name="dataurl" select="'books.xml'"/>
<xsl:variable name="bookdata" select="document($dataurl)"/>



<xsl:key name="k1" match="ex:book" use="ex:ID"/>

<xsl:template match="/|@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="book">
<xsl:variable name="id" select="ID"/>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<xsl:for-each select="$bookdata">
<xsl:apply-templates select="key('k1', $id)/*[starts-with(local-name(), 'NewField')]"/>
</xsl:for-each>
</xsl:copy>
</xsl:template>






<xsl:template match="NewField1">

<DateClosed>

<xsl:value-of select="."/>
</DateClosed>

</xsl:template>


</xsl:stylesheet>



Structure of the second input doc:


<books xmlns=" xmlns="http://www.xxx.com/">
<book>
<ID>1</ID>
<NewField1>2007-10-01T00:00:00.000</NewField1>
<NewField2>2007-10-01T00:00:00.000</NewField2>
<NewField3>2007-10-01T00:00:00.000</NewField3>


</book>
<book>
<ID>2</ID>
<NewField1>2007-10-01T00:00:00.000</NewField1>
<NewField2>2007-10-01T00:00:00.000</NewField2>
<NewField3>2007-10-01T00:00:00.000</NewField3>

</book>

</books>
 
Old January 28th, 2010, 01:37 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I am afraid what you have posted as the second input doc, the
<books xmlns=" xmlns="http://www.xxx.com/">
is not even well-formed XML.

And what is the
<xsl:template match="NewField1">
in the stylesheet supposed to do? If the elements are in a namespace then that match="NewField1" will not match them as it matches elements in no namespace.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old January 28th, 2010, 01:44 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This isn't even well-formed XML

Code:
<books xmlns=" xmlns="http://www.xxx.com/">
and it certainly doesn't tally with your statement that you removed the namespace.

Try to do some active debugging yourself rather than just bouncing back and saying things don't work. Try playing around with the code to see which parts work and which don't.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old January 28th, 2010, 01:55 PM
Authorized User
 
Join Date: Jan 2010
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

<xsl:output encoding="UTF-8" method="xml"/>
<xsl:param name="dataurl" select="'books.xml'"/>
<xsl:variable name="bookdata" select="document($dataurl)"/>



<xsl:key name="k1" match="ex:book" use="ex:ID"/>

<xsl:template match="/|@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="book">
<xsl:variable name="id" select="ID"/>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<xsl:for-each select="$bookdata">
<xsl:apply-templates select="key('k1', $id)/*[starts-with(local-name(), 'NewField')]"/>
</xsl:for-each>
</xsl:copy>
</xsl:template>








</xsl:stylesheet>



Structure of the second input doc:

<books xmlns="http://www.xxx.com/">
<book>
<ID>1</ID>
<NewField1>2007-10-01T00:00:00.000</NewField1>
<NewField2>2007-10-01T00:00:00.000</NewField2>
<NewField3>2007-10-01T00:00:00.000</NewField3>


</book>
<book>
<ID>2</ID>
<NewField1>2007-10-01T00:00:00.000</NewField1>
<NewField2>2007-10-01T00:00:00.000</NewField2>
<NewField3>2007-10-01T00:00:00.000</NewField3>

</book>

</books>
 
Old January 28th, 2010, 02:02 PM
Authorized User
 
Join Date: Jan 2010
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sam and Martin,

Sorry to bug you..but I really need to get this out today..so that is why I am trying hard.


Thanks for all your help
 
Old January 28th, 2010, 02:04 PM
Authorized User
 
Join Date: Jan 2010
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Mike,

Sorry! here is my updated version with all the changes that Martin and Sam suggested:


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

<xsl:output encoding="UTF-8" method="xml"/>
<xsl:param name="dataurl" select="'books.xml'"/>
<xsl:variable name="bookdata" select="document($dataurl)"/>



<xsl:key name="k1" match="ex:book" use="ex:ID"/>

<xsl:template match="/|@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="book">
<xsl:variable name="id" select="ID"/>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<xsl:for-each select="$bookdata">
<xsl:apply-templates select="key('k1', $id)/*[starts-with(local-name(), 'NewField')]"/>
</xsl:for-each>
</xsl:copy>
</xsl:template>








</xsl:stylesheet>



Structure of the second input doc:

<books xmlns="http://www.xxx.com/">
<book>
<ID>1</ID>
<NewField1>2007-10-01T00:00:00.000</NewField1>
<NewField2>2007-10-01T00:00:00.000</NewField2>
<NewField3>2007-10-01T00:00:00.000</NewField3>


</book>
<book>
<ID>2</ID>
<NewField1>2007-10-01T00:00:00.000</NewField1>
<NewField2>2007-10-01T00:00:00.000</NewField2>
<NewField3>2007-10-01T00:00:00.000</NewField3>

</book>

</books>
 
Old January 28th, 2010, 02:05 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Does the first XML input also use a namespace? That way the xsl:template match="book" would never be applied.
But you keep us guessing. Post three well-formed, minimal but complete code samples of the two XML input documents and the XSLT stylesheet so that we can run them and reproduce the result you get and then fix the stylesheet.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old January 28th, 2010, 02:08 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

In your original first input XML document 'Book' is uppercase, but in this latest incarnation of the XSLT you have <xsl:template match="book"> which is lowercase.

Also, you might have a deadline, but we don't. The less work you put in to try and debug and come up with sensible questions the less likely we are too try to be helpful, so posting as fast as you can is not necessarily always the best approach.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Another question about generating XSLT with XSLT danblick XSLT 2 July 16th, 2009 08:40 PM
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
xslt with an xslt outputfile alleycat XSLT 4 February 20th, 2006 09:56 AM





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