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