This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Identifying two tags that share some attribute names andvalues


Hello Zack,

I have a solution, but I don't know whether it's the optimum. I didn't 
get it with one expression and need the step with $test:

<xsl:variable name="file1" select="/"/>
<xsl:variable name="file2" select="document('2.xml')/outsidedata"/>

<xsl:template match="/">
     <xsl:apply-templates select="$file2/b"/>
</xsl:template>

<xsl:template match="b">
     <xsl:variable name="test">
         <xsl:for-each select="@*">
             <xsl:if test="$file1/a/@*[name()=name(current())][. != 
current()] or not($file1/a/@*[name()=name(current())])">
                 <xsl:text>false</xsl:text>
             </xsl:if>
         </xsl:for-each>
     </xsl:variable>
     <xsl:if test="not(contains($test, 'false'))">
         <xsl:text>[</xsl:text>
         <xsl:value-of select="."/>
         <xsl:text>]</xsl:text>
     </xsl:if>
</xsl:template>

I test on every attribute whether it is in <a> and has a different value 
or it does completely not exist. If it is so I add a false to the 
test-string. If no 'false' is contained in $test, the value of b will be 
copied to the output.

Regards,

Joerg

Zack Brown schrieb:
> Hi folks,
> 
> I've been migrating the Kernel Traffic web site (http://kt.zork.net) over to an
> XML/XSLT-based production system. So far it looks like something I should have
> done years ago. Compilation time (compared with my old home-grown processor)
> has dropped from hours to minutes, and the flexibility to add new features
> is just amazing.
> 
> However, there are still a few things that are giving me problems. One such
> boils down to trying to identify a set of tags that share attributes with
> a target tag. So for instance I have two files, 1.xml and 2.xml:
> 
> ----------------------------- 1.xml ---------------------------------
> <?xml version="1.0" ?>
> 
> <mydata>
> <a x="1" y="2" z="3">test</a>
> </mydata>
> ---------------------------------------------------------------------
> 
> ----------------------------- 2.xml ---------------------------------
> <?xml version="1.0" ?>
> 
> <outsidedata>
> <b x="1" y="2">PPP</b>
> <b y="2" z="3">QQQ</b>
> <b z="3">RRR</b>
> <b x="9" y="8" z="7">SSS</b>
> <b m="2" z="3">TTT</b>
> </outsidedata>
> ---------------------------------------------------------------------
> 
> Basically, 1.xml represents a newsletter file, and 2.xml is an automatically
> generated file that contains cross-reference information. The <a> tag in
> 1.xml is a cross-reference request that needs to be resolved using data
> available in 2.xml.
> 
> processing is done on 1.xml, which reads in 2.xml via the document()
> function. The XSLT code analyzes 2.xml and looks for all <b> tags whose
> attributes precisely match attributes found in the target <a> tag. Note that
> not all of <a>'s attributes must be present in a matching <b>, but all of
> <b>'s attributes must be present in <a> and must share the same values as
> the corresponding attributes in <a>. Also note that <a>'s attributes are not
> necessarily "x", "y", and "z", but could be anything. The XSLT code should
> not make assumptions about their names or how many there may be.
> 
> So in the above example files, <a> contains attributes "x", "y", and "z",
> which each have the values "1", "2", and "3" respectively. Looking at 2.xml,
> you can see that the first, second and third <b> tags are successful matches,
> while the fourth and fifth are not.
> 
> What I need is a recipe like the following (except that works ;-):
> 
> ----------------- XSLT code for processing a.xml --------------------
> <!-- Resolve kcrefs -->
> <xsl:template match="mydata/a">
> <xsl:for-each select="document('2.xml')/outsidedata/b">
> [<xsl:value-of select="."/>]
> </xsl:for-each>
> </xsl:template>
> ---------------------------------------------------------------------
> 
> in which the output would look something like this:
> 
> ----------------------- Desired output ------------------------------
> [PPP]
> [QQQ]
> [RRR]
> ---------------------------------------------------------------------
> 
> I hope I've described this well enough. I don't even know if it's possible
> to do what I'm asking for, though it seems like it should be. Any help would
> be greatly appreciated.
> 
> Many thanks,
> Zack
> 



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]