Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML XSL Parsing problem with Xalan

Reply
Thread Tools

XML XSL Parsing problem with Xalan

 
 
littlefitzer
Guest
Posts: n/a
 
      09-14-2004
Hi,
I have come across a tricky little problem, I hope maybe one of you
can help.
The problem I am having is that I need to parse two seperate values
from an XML document using XSL. The two elements however are identical
in their names and XPath appearing as below in the XML (I have left
out XPath as they are the same):
<esb:AcctTypeCode>43</esb:AcctTypeCode>
<esb:AcctTypeCode>21</esb:AcctTypeCode>

To get around this problem I used template matching, one for each
value, in the XSL to get the values as follows:
<!-- getLoanTypeCode Template -->
<xsl:template name="getLoanTypeCode"
match="./AccountRecord/esb:LoanAcctInfo/esb:AcctTypeCode">
<xsl:for-each select="./AccountRecord/esb:LoanAcctInfo/esb:AcctTypeCode">
<xsl:if test="position()=1">
<xsl:value-of select="node()"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- END getLoanTypeCode Template -->
<!-- getOriginalLoanTypeCode Template -->
<xsl:template name="getOriginalLoanTypeCode"
match="./AccountRecord/esb:LoanAcctInfo/esb:AcctTypeCode">
<xsl:for-each select="./AccountRecord/esb:LoanAcctInfo/esb:AcctTypeCode">
<xsl:if test="position()=2">
<xsl:value-of select="node()"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- END getOriginalLoanTypeCode Template -->

The main problem I need to solve, and I the reason I have posted here
is:
This works fine when I test the transformation with XMLSpy, however,
this does not work when I use Xalan for the conversion. When I run the
code I get the following exception:
[9/14/04 9:19:40:324 MDT] 4791004a SystemErr R
javax.xml.transform.TransformerConfigurationExcept ion:
javax.xml.transform.TransformerConfigurationExcept ion:
javax.xml.transform.TransformerException:
javax.xml.transform.TransformerException: A node test that matches
either NCName:* or QName was expected.
at org.apache.xalan.processor.TransformerFactoryImpl. newTransformer(TransformerFactoryImpl.java:71
etc. etc.

I have tried this with a couple of versions of the Xalan and Xerces
jars including the ones from versions 2.6.0 and 2.6.2 of those
binaries so Idon't think it is a version problem, but it absolutely
has to do with the way I am getting the values because when I comment
out the template calls the parsing works fine (but obviously without
returning the values I want, if you know what I mean!).

Has anyone come across this problem before, or have any suggestions on
a possible fix or work-a-round?

Thanks,
littlefitzer
 
Reply With Quote
 
 
 
 
Johannes Busse
Guest
Posts: n/a
 
      09-15-2004
hi,

> The problem I am having is that I need to parse two seperate values
> from an XML document using XSL. The two elements however are identical
> in their names and XPath appearing as below in the XML (I have left
> out XPath as they are the same):
> <esb:AcctTypeCode>43</esb:AcctTypeCode>
> <esb:AcctTypeCode>21</esb:AcctTypeCode>


no, the XPath experssions are not the same. Try:

> <xsl:template name="getLoanTypeCode"
> match="./AccountRecord/esb:LoanAcctInfo/esb:AcctTypeCode[1]">
> <xsl:value-of select="node()"/>
> </xsl:template>


and

> <!-- getOriginalLoanTypeCode Template -->
> <xsl:template name="getOriginalLoanTypeCode"
> match="./AccountRecord/esb:LoanAcctInfo/esb:AcctTypeCode[2]">
> <xsl:value-of select="node()"/>
> </xsl:template>
> <!-- END getOriginalLoanTypeCode Template -->


this works with saxon 6.5.
johannes

 
Reply With Quote
 
 
 
 
littlefitzer
Guest
Posts: n/a
 
      09-15-2004
Thanks Johannes,
But I tried exactly what you say below, and I still get the same
error.
Also in XSMLSpy it did not work either - it returned a value of
'0InfoSuccess' for both.
Any other suggestions?




> no, the XPath experssions are not the same. Try:
>
> > <xsl:template name="getLoanTypeCode"
> > match="./AccountRecord/esb:LoanAcctInfo/esb:AcctTypeCode[1]">
> > <xsl:value-of select="node()"/>
> > </xsl:template>

>
> and
>
> > <!-- getOriginalLoanTypeCode Template -->
> > <xsl:template name="getOriginalLoanTypeCode"
> > match="./AccountRecord/esb:LoanAcctInfo/esb:AcctTypeCode[2]">
> > <xsl:value-of select="node()"/>
> > </xsl:template>
> > <!-- END getOriginalLoanTypeCode Template -->

>
> this works with saxon 6.5.
> johannes

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with <xsl:document> using xalan (jdk 1.5) Petterson Mikael XML 3 05-23-2007 04:53 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
Upgrade of Xalan 1.2.2 and Xerces 1.4.4 to Xalan 2.6 and Xerces 2.6.2 cvissy XML 0 11-16-2004 07:06 AM
XSL+XML=> HTML using xalan. bastien XML 0 05-25-2004 08:50 AM
xsl-fo and xml file to test xalan to create fo-file RoyalDutchman XML 0 12-17-2003 11:43 PM



Advertisments