Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old August 30th, 2011, 03:14 PM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Question using "following" causes problem

the input xml:
Code:
<ISA>  
  <GS>
    <ST>
      <SLN>
        <SLN01>1</SLN01>
        <SLN02>1</SLN02>
        <SLN03>A</SLN03>
        <SLN04>1</SLN04>
        <SLN05>EA</SLN05>
      </SLN>
      <N9>
        <N901>ME</N901>
        <N902>STAT</N902>
      </N9>
      <MTX>
        <MTX02>WORKING 20110803</MTX02>
      </MTX>
      <SLN>
        <SLN01>1</SLN01>
        <SLN02>2</SLN02>
        <SLN03>A</SLN03>
        <SLN04>1</SLN04>
        <SLN05>EA</SLN05>
      </SLN>
      <N9>
        <N901>82</N901>
        <N902>EXKEY</N902>
        <N903>603880</N903>
      </N9>
      <N9>
        <N901>82</N901>
        <N902>SWDESC</N902>
      </N9>
      <MTX>
        <MTX02>5ESS</MTX02>
      </MTX>
      <CTT>
        <CTT01>1</CTT01>
      </CTT>
    </ST>
  </GS>
</ISA>
The xsl codes which I use:
Code:
          <xsl:if test="N9[N901='82' and N902='SWDESC']/following::MTX/MTX02">
              <xsl:element name="Detail">
                <xsl:attribute name="tag">SWDESC</xsl:attribute>
                <xsl:attribute name="value">
                  <xsl:value-of select="N9[N901='82' and N902='SWDESC']/following::MTX/MTX02"/>
                </xsl:attribute>
              </xsl:element>
            </xsl:if>
            <xsl:if test="N9[N901='82' and N902='LN']/following::MTX/MTX02">
              <xsl:element name="Detail">
                <xsl:attribute name="tag">LN</xsl:attribute>
                <xsl:attribute name="value">
                  <xsl:value-of select="N9[N901='82' and N902='LN']/following::MTX/MTX02"/>
                </xsl:attribute>
              </xsl:element>
            </xsl:if>
            <xsl:if test="N9[N901='ME' and N902='STAT']/following::MTX/MTX02">
              <xsl:element name="Detail">
                <xsl:attribute name="tag">STAT</xsl:attribute>
                <xsl:attribute name="value">
                  <xsl:value-of select="N9[N901='ME' and N902='STAT']/following::MTX/MTX02"/>
                </xsl:attribute>
              </xsl:element>
            </xsl:if>
Then, the java program which is use the xsl throws ArrayIndexOutOfBoundException. I found when the xsl code checks the fields in the xml, if the element is not there, like "LN", then the program throws exception, if the element there, it can work. I also found if I remove the "/folloing::MTX/MTX02" in the "if", then it can work, no matter the element in the xml or not. Why? And is there any alternative method to that?

(Note: the elements in the xml may in there or not, so I need the xsl to check whether these elements are there, if there, then output as Detail, if not there, then do nothing.)

Thanks.

Last edited by JohnKiller; August 30th, 2011 at 05:38 PM..
 
Old August 30th, 2011, 03:18 PM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Default

I found there is duplicate post, probably caused by the Internet connection. How to delete the duplicate one? Thanks.
 
Old August 30th, 2011, 04:35 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Which XSLT processor are you using?

An ArrayIndexOutOfBounds exception indicates a bug, which should be reported through the appropriate support channel for the product that you are using.

Check the stack trace to be sure the crash really is in the XSLT processor.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 30th, 2011, 05:37 PM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Hi, Michael,
I am using XSL 1.0 processor.

If the xsl code like below(remove the "following" part in the "if" ), then they can work, no matter whether the elements are there in the xml or not.
Code:
          <xsl:if test="N9[N901='82' and N902='SWDESC']">
              <xsl:element name="Detail">
                <xsl:attribute name="tag">SWDESC</xsl:attribute>
                <xsl:attribute name="value">
                  <xsl:value-of select="N9[N901='82' and N902='SWDESC']/following::MTX/MTX02"/>
                </xsl:attribute>
              </xsl:element>
            </xsl:if>
            <xsl:if test="N9[N901='82' and N902='LN']">
              <xsl:element name="Detail">
                <xsl:attribute name="tag">LN</xsl:attribute>
                <xsl:attribute name="value">
                  <xsl:value-of select="N9[N901='82' and N902='LN']/following::MTX/MTX02"/>
                </xsl:attribute>
              </xsl:element>
            </xsl:if>
            <xsl:if test="N9[N901='ME' and N902='STAT']">
              <xsl:element name="Detail">
                <xsl:attribute name="tag">STAT</xsl:attribute>
                <xsl:attribute name="value">
                  <xsl:value-of select="N9[N901='ME' and N902='STAT']/following::MTX/MTX02"/>
                </xsl:attribute>
              </xsl:element>
            </xsl:if>
In the question I posted, there are "following" part in "if" to check whether the element is exist or not.

And the crash stack trace is below, in the crash trace, we can see that the error has happened when using the transformer function.

Code:
javax.xml.transform.TransformerException: java.lang.ArrayIndexOutOfBoundsException: -1
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:716)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
      at preorder.XslResponseProcessor.transformResponse(XslResponseProcessor.java:81)
      at preorder.webservice.invoker.IaEdiInvoker.genericValidateAddress(IaEdiInvoker.java:253)
      at preorder.webservice.invoker.IaEdiInvoker.validateAddress(IaEdiInvoker.java:123)
      at preorder.webservice.AddressValidationByAddressRequest.submitThisRequest(AddressValidationByAddressRequest.java:713)
      at preorder.webservice.AddressPreorderRequest.submitRequest(AddressPreorderRequest.java:179)
      at preorder.webservice.GenericPreorderRequest.processRequest(GenericPreorderRequest.java:108)
      at preorder.webservice.AddressValidationByAddressRequest.main(AddressValidationByAddressRequest.java:549)
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
      at com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM2._type2(SAX2DTM2.java:1989)
      at com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM2$FollowingIterator.setStartNode(SAX2DTM2.java:1075)
      at com.sun.org.apache.xalan.internal.xsltc.dom.StepIterator.setStartNode(StepIterator.java:95)
      at com.sun.org.apache.xalan.internal.xsltc.dom.StepIterator.setStartNode(StepIterator.java:91)
      at GregorSamsa.template$dot$0()
      at GregorSamsa.applyTemplates()
      at GregorSamsa.applyTemplates()
      at GregorSamsa.applyTemplates()
      at GregorSamsa.applyTemplates()
      at GregorSamsa.transform()
      at com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet.transform(AbstractTranslet.java:603)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:709)
      ... 8 more
---------
java.lang.ArrayIndexOutOfBoundsException: -1
      at com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM2._type2(SAX2DTM2.java:1989)
      at com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM2$FollowingIterator.setStartNode(SAX2DTM2.java:1075)
      at com.sun.org.apache.xalan.internal.xsltc.dom.StepIterator.setStartNode(StepIterator.java:95)
      at com.sun.org.apache.xalan.internal.xsltc.dom.StepIterator.setStartNode(StepIterator.java:91)
      at GregorSamsa.template$dot$0()
      at GregorSamsa.applyTemplates()
      at GregorSamsa.applyTemplates()
      at GregorSamsa.applyTemplates()
      at GregorSamsa.applyTemplates()
      at GregorSamsa.transform()
      at com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet.transform(AbstractTranslet.java:603)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:709)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
      at preorder.XslResponseProcessor.transformResponse(XslResponseProcessor.java:81)
      at preorder.webservice.invoker.IaEdiInvoker.genericValidateAddress(IaEdiInvoker.java:253)
      at preorder.webservice.invoker.IaEdiInvoker.validateAddress(IaEdiInvoker.java:123)
      at preorder.webservice.AddressValidationByAddressRequest.submitThisRequest(AddressValidationByAddressRequest.java:713)
      at preorder.webservice.AddressPreorderRequest.submitRequest(AddressPreorderRequest.java:179)
      at preorder.webservice.GenericPreorderRequest.processRequest(GenericPreorderRequest.java:108)
      at preorder.webservice.AddressValidationByAddressRequest.main(AddressValidationByAddressRequest.java:549)

Last edited by JohnKiller; August 30th, 2011 at 05:43 PM..
 
Old August 30th, 2011, 06:49 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Raise a bug against the JDK, citing XSLTC as the offending component. While you are waiting for a response (my experience is that it usually takes 18 months), switch to Saxon.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
JohnKiller (August 31st, 2011)
 
Old August 30th, 2011, 07:09 PM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Michael,
Can you sure it is a bug of JDK, although I works with Java, but I am not familiar within the JDK.

If so, how can I report that bug?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Base Page Problem with "safeitenames" carryover in the 'inherits" johnandrewmcknight BOOK: Beginning ASP.NET 4 : in C# and VB 3 April 22nd, 2011 04:08 PM
MSXSL gives error message for "for" inside "select" ilyaz XSLT 1 December 9th, 2010 05:02 PM
How to theme the "Browse" button of "FileUpload" control? varunbwj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 October 14th, 2009 01:22 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 03:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.