 |
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
|
|
|

October 12th, 2006, 05:21 AM
|
Friend of Wrox
|
|
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Returning a value
Hi,
I need to retreive the 'Formatted Value' and 'Value' from the following xml:
Code:
<FormattedReportObjects>
<FormattedReportObject xsi:type="CTFormattedField" Type="xsd:string" FieldName="{@INVOICE_NUMBER}">
<ObjectName>INVOICENUMBER1</ObjectName>
<FormattedValue>9</FormattedValue>
<Value>9</Value>
</FormattedReportObject>
</FormattedReportObjects>
I have tried to populate a variable using the example:
Code:
<xsl:variable name="strInvNo" select=".//*[@FieldName='{@INVOICE_NUMBER}']/FormattedValue"/>
But there is no value returned, please can you assist?
Thanks,
Neal
A Northern Soul
__________________
Neal
A Northern Soul
|

October 12th, 2006, 05:36 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Given that your XML doesn't contain a namespace declaration for "xsi", I strongly suspect that you haven't shown us the whole of the XML, and my guess is that somewhere in the XML there is a default namespace declaration, which would mean that in your path expression, FormattedValue needs to be prefixed. That's extrapolating from very little evidence, but otherwise, what you've shown us seems correct.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|

October 12th, 2006, 06:04 AM
|
Friend of Wrox
|
|
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Hi,
Sorry, I am using version 1.0 and the full path is:
Code:
<FormattedReport xmlns="urn:crystal-reports:schemas" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
<FormattedAreaPair Level="0" Type="Report">
<FormattedArea Type="Header">
<FormattedSections>
<FormattedSection SectionNumber="0">
<FormattedReportObjects>
<FormattedReportObject xsi:type="CTFormattedField" Type="xsd:string" FieldName="{@INVOICE_NUMBER}">
<ObjectName>INVOICENUMBER1</ObjectName>
<FormattedValue>9</FormattedValue>
<Value>9</Value>
Neal
A Northern Soul
|

October 12th, 2006, 06:10 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
So I guessed right. The elements are in namespace xmlns="urn:crystal-reports:schemas" so you need to use a prefix on element names in the path expression. If in doubt google for "XSLT default namespace prefix".
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|

October 12th, 2006, 06:52 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
|

October 13th, 2006, 10:04 AM
|
Friend of Wrox
|
|
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Hi,
version 1.0
Thanks Mike for your assistance.
I have how managed to retreive data from my XML file. However, whereas the following will produces ALL node values:
Code:
.//*[@FieldName='{INVOICE_NUMBER}']/*
My original code returns no values:
Code:
.//*[@FieldName='{INVOICE_NUMBER}']/FormattedValue
Why is this?
Thanks in advance.
Neal
A Northern Soul
|

October 13th, 2006, 11:41 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
As explained previously, the FormattedValue element is in a namespace so it needs to be prefixed.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
 |