Re: [xsl] CATCH ALL | template rule (2nd try)

Subject: Re: [xsl] CATCH ALL | template rule (2nd try)
From: Karl Stubsjoen <kstubs@xxxxxxxxx>
Date: Tue, 17 May 2005 17:09:19 -0700
Sorry, I didn't get it : (
I am close... but picking exceptions that arent' exceptions. I changed
the apply-templates from above to this (in a desperate attempt to make
it work):

  <xsl:apply-templates select="fx:node-set($interval)
     [not(count(.|$scenario_a) = count($scenario_a))]
     [not(count(.|$scenario_b) = count($scenario_b))]
     [not(count(.|$scenario_c) = count($scenario_c))]
     [not(count(.|$scenario_d) = count($scenario_d))]
     [not(count(.|$scenario_e) = count($scenario_e))]"
  mode="Exceptions"/>

and then set up the following matches:

<xsl:template match="fn:interval" mode="Exceptions">
<xsl:variable name="current_interval"
select="ancestor::fn:interval/@current_interval"/>
<xsl:comment>EXCEPTION</xsl:comment>
  <xsl:copy-of select="."/>
</xsl:template>

next 2 templates hide the "junk":

<xsl:template match="fn:record" mode="Exceptions"/>
<xsl:template match="node()" mode="Exceptions"/>

Please help, I am not sure where to go from here.  My scenario_a data
appears in both the applied rule (above exceptions) and in exceptions.
 Also, I have setup an ABC example which does work properly (much
simple than my real data) but am confused as to why the real data is
not working.

Thanks,

Karl..






On 5/17/05, Karl Stubsjoen <kstubs@xxxxxxxxx> wrote:
> I got it:
> (without the node() match below i was getting the extra junk.. now it
> is suppressed)
> Thanks DIMITRE!  This is a kick ass solution!
>
> <xsl:apply-templates select="fx:node-set($interval)//node()
>    [not(count(.|$scenario_a) = count($scenario_a))]
>    [not(count(.|$scenario_b) = count($scenario_b))]
>    [not(count(.|$scenario_c) = count($scenario_c))]
>    [not(count(.|$scenario_d) = count($scenario_d))]
>    [not(count(.|$scenario_e) = count($scenario_e))]"
>  mode="Exceptions"/>
>
> <xsl:template match="fn:record" mode="Exceptions">
>  <xsl:comment>EXCEPTION</xsl:comment>
>  <xsl:copy-of select="."/>
> </xsl:template>
>
> <xsl:template match="node()" mode="Exceptions"/>
>
>
> On 5/17/05, Karl Stubsjoen <kstubs@xxxxxxxxx> wrote:
> > becomes:
> > fx:node-set($interval)[not(count(. | yourExpression) =
> > count(yourExpression))]
> >
> > (lose the "whack whack")
> >
> > On 5/17/05, Karl Stubsjoen <kstubs@xxxxxxxxx> wrote:
> > > I figured out the extra junk problem, we were at the wrong context of
> > > $interval on the apply exclusions.  This context is at:  fn:interval,
> > > so I removed the node() from the apply-templates so this:
> > > fx:node-set($interval)//node()[not(count(. | yourExpression) =
> > > count(yourExpression))]
> > >
> > > becomes:
> > > fx:node-set($interval)//[not(count(. | yourExpression) =
> > > count(yourExpression))]
> > >
> > > Junk is gone.  Does this seem correct, or is "node()" a very important
> > > aspect to this xpath?
> > >
> > >
> > > On 5/17/05, Karl Stubsjoen <kstubs@xxxxxxxxx> wrote:
> > > > Ahh Dimitre, quit teasing me with that XSLT 2.0 stuff!
> > > >
> > > > It is working great!  Except... I am getting additional junk.  Not
> > > > sure where it is coming from.  Like an apply-templates with no match
> > > > and you just get the text of the elements back.  I have set up empty
> > > > match templates for my mode of "Exceptions", it helped some, but I'm
> > > > still getting back extra junk.  In my "simple example" I am not
> > > > getting back the extra junk.  Any ideas?
> > > >
> > > >
> > > > On 5/17/05, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
> > > > > On 5/18/05, Karl Stubsjoen <kstubs@xxxxxxxxx> wrote:
> > > > > > Okay, I am going to try that!  How about this simpler example
> > > > > > though..., would you mind providing the inverse for this one:
> > > > > >
> > > > > > <xsl:template match="A">
> > > > > > <xsl:copy>
> > > > > >  <match>
> > > > > >    <xsl:apply-templates
select="B[X[@val=$match_v1]][X[@val=$match_v2]]"/>
> > > > > >  </match>
> > > > > >  <exception>
> > > > > >    <!-- currently, copy of the match above, but would like this to
be
> > > > > > expressed as the exception -->
> > > > > >    <xsl:apply-templates
select="B[X[@val=$match_v1]][X[@val=$match_v2]]"/>
> > > > > >  </exception>
> > > > > > </xsl:copy>
> > > > > > </xsl:template>
> > > > >
> > > > > N.P.
> > > > >
> > > > > This can be done mechanically:
> > > > >
> > > > > >    <xsl:apply-templates
select="B[X[@val=$match_v1]][X[@val=$match_v2]]"/>
> > > > >
> > > > >  <xsl:variable name="x"
select="B[X[@val=$match_v1]][X[@val=$match_v2]]"/>
> > > > >
> > > > >   <xsl:apply-templates select="node()[not(count(.|$x) =
count($x))]"/>
> > > > >
> > > > > Of course, in XPath 2.0 one will use the except operator:
> > > > >
> > > > >   <xsl:apply-templates select="node() except $x"/>
> > > > >
> > > > > Cheers,
> > > > > Dimitre
> > > > >
> > > > >
> > > > > >
> > > > > >
> > > > > > On 5/17/05, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
> > > > > > > > <xsl:apply-templates
> > > > > > > >
select="fx:node-set($interval)//fn:interval[//field[@fieldname='EntityID']=$F
TEInterval_Members][//field[@fieldname='EntityID']=$FTEInterval_JTED_Mains]"
> > > > > > > > mode="Exceptions" />
> > > > > > > >
> > > > > > > > What is the inverse of this?  Which would suffice to be my
"CATCH
> > > > > > > > ALL", in otherwords match everything else where the above
combination
> > > > > > > > fails.
> > > > > > >
> > > > > > > fx:node-set($interval)//node()[not(count(. | yourExpression) =
> > > > > > > count(yourExpression))]
> > > > > > >
> > > > > > > generally, if there are two node-sets: $ns1 and $ns2, their set
difference
> > > > > > >    $ns2 - $ns1
> > > > > > > is expressed by this XPath expression:
> > > > > > >
> > > > > > >    $ns2[not(count(. | $ns1) = count($ns1) ) ]
> > > > > > >
> > > > > > > Cheers,
> > > > > > > Dimitre

Current Thread