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

Re: Identifying two tags that share some attribute nam

Subject: Re: Identifying two tags that share some attribute names andvalues
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Sun, 05 May 2002 20:17:05 +0200
xsl identifying for each
> I apologize for this, but it looks like I slightly misstated the
> problem. I tested your solution and it looks like exactly what I'm
> looking for, with one difference: it is not <a> that contains the
> superset of attributes, with <b> containing a subset. It's actually
> <b> that contains the superset, and <a> contains the subset.
>
> This variation seems to work for me:
>
> <xsl:variable name="file2" select="document('2.xml')/outsidedata"/>
> <xsl:template match="a">
> <xsl:variable name="a" select="." />
> <xsl:for-each select="$file2/b[@* = $a/@*]">
> <xsl:variable name="b" select="." />
> <xsl:variable name="test">
> <xsl:for-each select="$a/@*">
> <xsl:if test="not($b/@*[name() = name(current())] = .)">
> no attribute with the same name on element b whose value equals this one
> </xsl:if>
> </xsl:for-each>
> </xsl:variable>
> <xsl:if test="not(string($test))">
> [<xsl:value-of select="."/>]
> </xsl:if>
> </xsl:for-each>
> </xsl:template>


Hi Zack,

I don't understand why Jeni's solution should be wrong. With your sentence

<p>The quick brown <a x="1" y="2" z="3">fox</a> jumps over the lazy <a x="9" y="8" z="7">dog</a>.</p>

and the second file

<outsidedata>
  <b x="1" y="2">PPP</b>
  <b y="2" z="3">QQQ</b>
  <b z="3">RRR</b>
  <b x="9" z="7">SSS</b>
  <b m="2" z="3">TTT</b>
</outsidedata>

I get the output

"The quick brown [PPP][QQQ][RRR] jumps over the lazy [SSS]."

This is exactly what I expect after reading your first posting again. With your stylesheet I get

"The quick brown jumps over the lazy ."

This seems not to be ok. I thought that the <b>s must not have all attributes from <a>, but may not have other than <a> and not the same with a different value.

And my comments/questions to Jeni's stylesheet:

>><xsl:template match="a">
>>  <xsl:variable name="a" select="." />
<xsl:for-each select="$file2/b[@* = $a/@*]">

I thought of a filter too, but I didn't find a sensible one. The above one isn't completely logical to me. What exactly does it mean? Maybe "all <b>s, whose all attributes are in <a> and don't have a different value"?


   <xsl:variable name="test">
     <xsl:for-each select="@*">
       <xsl:if test="not($a/@*[name() = name(current())] = .)">

This is a little bit easier ;-)


         no attribute with the same name on element a whose value
         equals this one
       </xsl:if>
     </xsl:for-each>
   </xsl:variable>
   <xsl:if test="not(string($test))">

This is easier again. Of course a test on "contains($test, 'false')" is not necessary.


     <xsl:text />[<xsl:value-of select="." />]<xsl:text />
   </xsl:if>
 </xsl:for-each>
</xsl:template>

Joerg



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.