[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: convert large array to several smaller arrays cont

Subject: Re: convert large array to several smaller arrays containing max N elements
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 11 Nov 2003 18:03:36 -0500
convert array to xml
David,

This is where you code is broken:

At 05:14 PM 11/11/2003, you wrote:
      <xsl:if test="position() mod 2 = '0'">
         </topgroup>
         <topgroup>
      </xsl:if>

This is not well-formed XML. The parser is seeing the </topgroup> end tag here; its error message is complaining that it's the wrong end tag. The only end tag allowed where you have "</topgroup>" is </xsl:if>.


So, you ask, what do I do if I can't "close" an element and "open" another one? Hint: XSLT is not a set of string-writing routines, and it doesn't work by writing tags to the output. Instead, it builds trees. Instead of

<xsl:template match="/">
<topgroup>
<xsl:for-each select="//WorkOrder/lineService">
<TEABTN>
<NPA><xsl:value-of select="normalize-space(tpExistAcctBillTelNo/npa)"/></NPA>
<NXX><xsl:value-of select="normalize-space(tpExistAcctBillTelNo/nxx)"/></NXX>
<XXXX><xsl:value-of select="normalize-space(tpExistAcctBillTelNo/xxxx)"/></XXXX>
</TEABTN>
<xsl:if test="position() mod 2 = '0'">
</topgroup>
<topgroup>
</xsl:if>
</xsl:for-each>
</topgroup>
</xsl:template>

you want something like


<xsl:template match="/">
<xsl:for-each select="//WorkOrder/lineService[position() mod 2 = 1]">
<topgroup>
<xsl:for-each select=".|following-sibling::lineService[1]">
<TEABTN>
<NPA><xsl:value-of select="normalize-space(tpExistAcctBillTelNo/npa)"/></NPA>
<NXX><xsl:value-of select="normalize-space(tpExistAcctBillTelNo/nxx)"/></NXX>
<XXXX><xsl:value-of select="normalize-space(tpExistAcctBillTelNo/xxxx)"/></XXXX>
</TEABTN>
</topgroup>
</xsl:for-each>
</xsl:template>


The difference between this and what you had is that it specifies a set of *nodes* to be added to the result *tree* -- not just write a bunch of tags (which hopefully will parse). Not incidentally, the stylesheet template itself is well-formed XML, and will parse.

It's completely different from, say, the way Javascript writes HTML tagging to browser windows.

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.