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: Can't Obtain Results


Hi Lindy,

> This is a repost to my previous messages. I have had to replace the
> greater than sign with the # sign so it can be sent through this
> mail client.

You could try using < in your mail client -- it sounds as though
it's expecting you to use HTML, in which case < should be passed
through as a less-than sign.

> I am passing in a parameter called outlet
>
> If the outlet parameter is "cb" - after transformation I want it to
> look like this:
>
>  #root>
>    #keyset>
>      #f1>some text#/f1>
>      #f2>SOMETEXT#/f2>
>      #f3>SOMETEXT#/f3>
>      #f4> SOMETEXT#/f4>
>      #f5> SOMETEXT#/f5>
>      #f6>some text#/f6>
>    #/keyset>
>  #/root>
>
> If the outlet parameter is "default" - after transformation I want
> it to look like this:
>
>  #root >
>    #keyset >
>      #f1>some text#/f1>
>      #f2>some text#/f2>
>      #f3>some text#/f3>
>      #f6>some text#/f6>
>    #/keyset>
>  #/root>

It appears to me that the rule is that you want f1 to f6 elements to
appear, containing the value from the keyset with the correct outlet
if there is one, the value from the keyset without an outlet attribute
if there isn't one, or not appearing at all if neither keyset contains
a value.

In which case, you should have a template that will do the right thing
for a given element name, something like:

<xsl:param name="outlet" select="'cb'" />

<xsl:template name="showElement">
  <xsl:param name="elementName" />
  <xsl:variable name="value" select="/root/keyset[@outlet = $outlet]
                                       /*[name() = $elementName]" />
  <xsl:choose>
    <xsl:when test="$value">
      <xsl:copy-of select="$value" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:variable name="defaultValue"
        select="/root/keyset[not(@outlet)]/*[name() = $elementName]" />
      <xsl:if test="$defaultValue">
        <xsl:copy-of select="$defaultValue" />
      </xsl:if>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Then you need to call this template to create the elements f1 to f6:

<xsl:template match="/">
  <xsl:call-template name="showElement">
    <xsl:with-param name="elementName" select="'f1'" />
  </xsl:call-template>
  <xsl:call-template name="showElement">
    <xsl:with-param name="elementName" select="'f2'" />
  </xsl:call-template>
  ...
  <xsl:call-template name="showElement">
    <xsl:with-param name="elementName" select="'f6'" />
  </xsl:call-template>
</xsl:template>

If you don't want to hard-code the element names like this, then you
need to come up with an algorithm that you can use to get hold of the
names of the elements in the order that you want them. This is quite
difficult with your XML design; it really requires a grouping
solution, as far as I can see. Let us know if you need to do that,
particularly if your elements aren't really called 'f1' to 'f6'...

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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]