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





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.