xsl-list
[Top] [All Lists]

Re: [xsl] Writing array elements based on a an evaluation of one of the child elements

2006-05-24 05:36:10
On 5/24/06, neil cave <coraltrees(_at_)yahoo(_dot_)co(_dot_)uk> wrote:
So now I have...

 <xsl:template match = "ACCOUNT-LIST">
   <xsl:if test="string-length(ACCOUNT-NO/text() > 0)">
   <xsl:element name = "ACCOUNT-LIST">
                       <xsl:for-each select="."/>
            </xsl:element>
       </xsl:if>
 </xsl:template>

and this writes a whole bunch of empty <ACCOUNT-LIST> elements
Which I guess is happening
              ^^^^^^^^^^^^^^
Well, guessing isn't going to help much.

 because somehow I'm not refering to the correct occurence of the ACCOUNT-NO child 
> > node I'm dealing with? And I'll need some xsl:for-each logic
Why the for-each?  Why wouldn't you be referring to the correct
occurence.  Not likely we'll know unless you actually show the input.

I see the xsl above as saying...

When you see the ACCOUNT-LIST element
1) check if the child element ACCOUNT-NO has a text length gt; 0
2) If yes write an element called ACCOUNT-LIST that has all the values of the 
current node (ACCOUNT-LIST).

Well, change 1) to say check if the first text child of ACCOUNT-NO has
a length of 0, which David Carlisle already pointed out is pointless
since it wouldn't be created if it didn't.

I guess I'm mising a whole chunk that specifies the current occurence
 ^^^ that darn word again.

Well, without any example of input and only having vaguely folllowed
this thread, I'll have to do some guess of my own.

What is the text length between the dashes?:  -    -
What is the text length between these dashes?: -
-

The point I'm trying to make is that XSLT will count the whitespace.
If you think it shouldn't, you need to tell it not too.  Notice too
you've ignored the advice of several people on the list and are still
just getting the first text node.  If you read the specs you'll find
more information about string manipulation and how to get the string
value.  (The xslt 1.0 really is readable)  The short answer can also
be found in the FAQ (Under Empty Elements -> Testing for Empty
elements).  You need to normalize the space of the text value of the
element.

Also it sounds like you'll always create Account-List but not
necessarily Account-No.  So why are you bothering with that this in
the template for account list?

So anyhow, combining the advice

<xsl:template match="ACCOUNT-LIST">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>

<xsl:template match="ACCOUNT-NO">
<xsl:if test="normalized-space(.)">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:if>
</xsl:template>


Now if you want to make sure you understand the points, make sure you
understand the difference between getting the string value of
ACCOUNT-NO and getting the child text nodes of ACCOUNT-NO.  Then
remember that whitespace counts in XML since one of it's roles is in
the markup of documents.

Jon Gorman






----- Original Message ----
From: Florent Georges <darkman_spam(_at_)yahoo(_dot_)fr>
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Sent: Wednesday, 24 May, 2006 1:31:01 PM
Subject: Re: [xsl] Writing array elements based on a an evaluation of one of 
the child elements


neil cave wrote:

> THat and the fact that I should be evaluating

> string-length(//ACCOUNT-NO/text()) > 0 )

  It depends on your input type and on what you want exactly to test.
But in this case, I think you can just test the presence of the text
nodes (not their length being gt 0).  It looks quite strange to me to
test on all ACCOUNT-NO in the document.  But you're the only one that
knows.

  Regards,

--drkm




























___________________________________________________________________________
Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son interface 
révolutionnaire.
http://fr.mail.yahoo.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--