xsl-list
[Top] [All Lists]

Re: [xsl] would like to simplify my XSLT

2007-01-29 20:27:21
This solved it nicely--thanks George.  It will give me
people who don't have any documents at all, but that's
actually OK for my needs--I just added that caveat
last-second because I (incorrectly, it turns out)
thought it might simplify matters.

Glen

--- George Cristian Bina <george(_at_)oxygenxml(_dot_)com> wrote:

Hi Glen,

<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0">
   <xsl:template match="/">
     <people>
       <xsl:for-each select="data/persons/person">
         <xsl:if

test="not(document[(_at_)relid=/data/documents/document/@id])">
           <name><xsl:value-of
select="name"/></name>
         </xsl:if>
       </xsl:for-each>
     </people>
   </xsl:template>
</xsl:stylesheet>

Regards,
George

---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT
Editor/Debugger
http://www.oxygenxml.com


Glen Mazza wrote:
The following XSLT 1.0 code *works*, but I think
it
can be greatly simplified--I just don't know the
construct needed for the simplification.

Given an XML such as this:
<data>
<documents>
  <document id="1"/>
  <document id="2"/>
</documents>
<persons>
  <person>
        <name>Chris</name>
    <document relid="4"/>
    <document relid="7"/>
  </person>
  <person>
        <name>John</name>
    <document relid="2"/>
  </person>
</persons>
</data>

I want to list all people who *have* documents but
do
*not* have at least one document that is in the
<documents> list.  For example, Chris above has no
documents in the <documents> list (relid=4 and 7
aren't there), so he would get listed, but John
above
wouldn't, because his "2" is in the list.

This is what I've done (pseudocode, so might have
minor errors):

<xsl:for-each select="/persons/person">
<xsl:variable name="v_DocumentFound">
    <xsl:for-each select="document">
       <xsl:variable name="v_relid"
select="@relid"/>
       <xsl:if test="count(/documents/document[(_at_)id
=
$v_relid]) > 0">
           <xsl:text>(document found)</xsl:text>
       </xsl:if>
    </xsl:for-each>
</xsl:variable>
<xsl:if
test="not(boolean(translate($v_DocumentFound,
' ', '')))">
      Document was not found for <xsl:value-of
select="name"/>
</xsl:if>
</xsl:for-each>

In other words, I stuff a variable named
$v_DocumentFound with text each time a document
match
is found, then check whether the variable is empty
to
see whether or not I need to report something.

Is this the right way of doing what I am trying to
accomplish--or is there a simpler method?  Mine
seems
verbose, like I'm missing something obvious.

Thanks,
Glen



 


____________________________________________________________________________________
Food fight? Enjoy some healthy debate 
in the Yahoo! Answers Food & Drink Q&A.


http://answers.yahoo.com/dir/?link=list&sid=396545367



--~------------------------------------------------------------------
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>
--~--





 
____________________________________________________________________________________
Bored stiff? Loosen up... 
Download and play hundreds of games for free on Yahoo! Games.
http://games.yahoo.com/games/front

--~------------------------------------------------------------------
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>
--~--