XML XSL Parsing problem with Xalan

L

littlefitzer

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.TransformerConfigurationException:
javax.xml.transform.TransformerConfigurationException:
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:718)
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
 
J

Johannes Busse

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
 
L

littlefitzer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top