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

Re: Re: Defining a Variable that depends on an unknown

Subject: Re: Re: Defining a Variable that depends on an unknown number of conditions
From: "Andrew Ferk" <andrewferk@xxxxxxxxx>
Date: Thu, 1 Jan 2009 19:40:31 -0600
Re:  Re: Defining a Variable that depends on an unknown
> OK.  I'm trying to determine if element_x or element_y contain the
> value value_m or value_n.
> I believe I'm close, but can't figure out what to replace ____________ with.
> I tried current()/../@on and ./../@on but no luck.
>
> Thanks.  Below is a quick mock-up of files.
>
> I have xml_a.xml as so:
> <xml_a>
>  <depends>
>    <depend on="element_x" equals="value_m|value_n"/>
>    <depend on="element_y" equals="value_m|value_n"/>
>  </depends>
> </xml_a>
>
> and xml_b.xml:
> <xml_b>
>  <element_x>value_m</element_x>
>  <element_y>value_p</element_y>
> </xml_b>
>
> finally transform.xsl, that opens xml_b.xml and transforms xml_a.xml.
> <xsl:variable name="xml_b" select="document('xml_b.xml')/xml_b"/>
> <xml:template select="xml_a">
>  <xsl:variable name="my_test" select =
> "depends/depend/@equals[contains(.,$xml_b/*[name()=__________])]"/>
> </xml:template>

I solved my problem using a recursive template.

<xsl:variable name="xml_b" select="document('xml_b.xml')/xml_b"/>

<xsl:template name="loop">
  <xsl:param name="loop_variable">1</xsl:param>
  <xsl:parram name="attr_on">
    <xsl:value-of select="depends/depend[position()=$loop_variable]/@on"/>
  </xsl:param>
  <xsl:param name="attr_equals">
    <xsl:value-of select="depends/depend[position()=$loop_variable]/@equals"/>
  </xsl:param>

  <xsl:choose>
    <xsl:when test="$attr_on = ''">yes</xsl:when>
      <xsl:when test="$xml_b/*[name()=$attr_on] = ''">
        <xsl:call-template name="depends">
          <xsl:with-param name="loop_variable" select="$loop_variable + 1"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:when test="contains($attr_equals,
$xml_b/*[name()=$attr_on])">no</xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="depends">
         <xsl:with-param name="loop_variable" select="$loop_variable + 1"/>
      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template select="xml_a">
  <xsl:variable name="my_test">
    <xsl:call-template name="loop"/>
  </xsl:variable>
</xsl:template>

-- 
Andrew Ferk

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.