xsl-list
[Top] [All Lists]

RE: Close but a little off

2003-04-16 13:57:17
[Karl J. Stubsjoen]

This is too unclear to try to fix without more information, like what
the source xml looks like, and what you want to accomplish.  You have
"xml" referred to one time as a relative path, one time with a "//", and
one time with a "/'.  This makes it very uncertain whether "xml" is the
document element or not.

Also, there is no relation between the for-each block and the row
matched by the template, so what you are showing seems pointless (I am
sure there _is_ a point, though, hence the need for more info).  You
said you wanted a "match" - but not what that is supposed to mean - and
you show no effort to include any "match" in your template.

However, there are a few observations to make, even without knowing
answers to the above items.  First of all, use variables.  Assuming that
there are some number of rows (more than one), create a variable for
//xml/s:Schema/s:ElementType/s:AttributeType and re-use it so its
node-set only needs to be evaluated once.  Also, why start that path
with "//"?  Unless your source xml is pretty unusual, that expression
can only slow down the processing without adding any value.

You can make use of expressions from outside the for-each block by using
variables.  Thus -

<xsl:variable name='row-name' select='@name'/>

Then inside the for-each block,

<xsl:value-of select='$row-name'/>

But I suspect you may be wanting something more like

select="/xml/rs:data/z:row/@*[name() = $row-name]"

(although I do not quite see what you want to do with it once you get
it).  However, /xml/rs:data/z:row is a fixed path that you could also
put into a variable.  I imagine that you wish that path to track to path
shown in the match path of the template, but  it will not the way you
have shown in.

Finally, it is very unlikely that you need a compound path in the match
attribute.  You have 

match='xml/rs:data/z:row'

Except for very unusual cases, you just want to have 

match='z:row'

The rest of the context should be set by the select statement that
causes this template to be invoked.  If you want to have different
processong of a z:row depending on where you call it from, use modes on
the templates.

Cheers,

Tom P

I'm close, but just a little off and am not sure how to refer 
to the parent
(think its considered parent) xpath.
I have the following template:

<xsl:template match="xml/rs:data/z:row">
<table border="1">
 <xsl:for-each select="//xml/s:Schema/s:ElementType/s:AttributeType">
    <tr>
     <td><xsl:value-of select="@name"/></td>
     <td><xsl:value-of select="/xml/rs:data/z:row/@name"/>&nbsp;</td>
    </tr>
    </xsl:for-each>
</table>
</xsl:template>

In english, this translates to:
For each row loop throught the s:AttributeType node.  This 
node contains the
name of the attribute for the field, the size of the element, 
etc... I need
to return the name of the attribute and then use this name to 
match the
attribute in the original match "xml/rs:data/z:row".
I'm close... in my 2nd xsl:value-of, I'm not sure how to 
refer to the values
from the original match and not values which are coming from 
the for-each
loop.
Hope that makes sense.
Thanks,
Karl


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



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



<Prev in Thread] Current Thread [Next in Thread>