Hi Gerald,
At 12:04 PM 4/21/2004, you wrote:
I have the following XML Document:
<?xml version="1.0" encoding="UTF-8"?>
<input>
<add class-name="User">
<add-attr attr-name="jkuSLABS">
<value>90</value>
</add-attr>
<add-attr attr-name="jkuSLART">
<value>50</value>
</add-attr>
<add-attr attr-name="jkuPeHabd">
<value type="string">7777-33-11</value>
</add-attr>
</add>
</input>
What Id like to to is the get an output document which should contain
the
<add-attr attr-name="jkuPeHabd">
<value type="string">7777-33-11</value>
</add-attr>
only, if the jkuSLABS=90 AND jkuSLART=50. Otherwise the 3 lines should
be omitted.
I thought of the following, but I think I am misunderstanding
something:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[(_at_)attr-name='jkuPeHabd']">
<xsl:variable name="slart"
select="//*[(_at_)attr-name='jkuPeBeschSAP22SLART']//value"/>
<xsl:variable name="slabs"
select="//*[(_at_)attr-name='jkuPeBeschSAP22SLABS']//value"/>
<xsl:if test="($slart!='50') or ($slabs!='90')">
</xsl:if>
</xsl:template>
As far as I can see the if never gets true, but still if it would be
true, I would need some "else" operation. Maybe you can give me a hint
how to solve this.
The reason $slart != 50 never gets true is ... well it's impossible to say
without looking at your entire data set, since you have bound $slart to
//*[(_at_)attr-name='jkuPeBeschSAP22SLART']//value
-- which is to say, a whole lot of nodes. This XPath translates as "a value
anywhere inside an element with @attr-name=''jkuPeBeschSAP22SLART'
appearing anywhere in the document", but that's not what you want, I think.
From your description, I think you want
../*[(_at_)attr-name='jkuSLABS']/value
which is to say the value child of the element child with
@attr-name='jkuSLABS' of my parent.
Then I think you simply need
<xsl:if test="($slart = '50') and ($slabs = '90')">
<xsl:copy-of select="."/><!-- copy me and my descendants -->
</xsl:if>
with no 'else' since your 'else' case is to do nothing.
I hope that helps! First, take a hard look at an XPath tutorial and try to
determine why the XPaths you created will *not* work ... don't just guess;
look it up.
Cheers,
Wendell
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
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
======================================================================