XML XSL Parsing problem with Xalan

Discussion in 'XML' started by littlefitzer, Sep 14, 2004.

  1. littlefitzer

    littlefitzer Guest

    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
     
    littlefitzer, Sep 14, 2004
    #1
    1. Advertising

  2. 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
     
    Johannes Busse, Sep 15, 2004
    #2
    1. Advertising

  3. littlefitzer

    littlefitzer Guest

    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
     
    littlefitzer, Sep 15, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RoyalDutchman
    Replies:
    0
    Views:
    404
    RoyalDutchman
    Dec 17, 2003
  2. bastien

    XSL+XML=> HTML using xalan.

    bastien, May 25, 2004, in forum: XML
    Replies:
    0
    Views:
    492
    bastien
    May 25, 2004
  3. cvissy
    Replies:
    0
    Views:
    627
    cvissy
    Nov 16, 2004
  4. Replies:
    1
    Views:
    3,651
    A. Bolmarcich
    May 27, 2005
  5. Petterson Mikael
    Replies:
    3
    Views:
    1,004
    Martin Honnen
    May 23, 2007
Loading...

Share This Page