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]

Matching or testing dynamically created attributes


Hello to all. I have a problem that I have been working on for days and am
quite stumped. It is difficult to explain, so I'll include a short and long
version of my question.

Short version: While in a for-each loop, how can I match the current node's
attribute (say @NAME) against an attribute in another node somewhere else
without knowing that attribute's name? Essentially, "if the @NAME attribute
of this node is the same as an attribute in the node over there, do
something..." or, this NAME is "row1". if there is an attribute in the node
over there named "row1" what is its value?

Long Version: I am creating a expandable/collapsable menu. I have one static
XML page and one XML page that is dynamically created. The static page
consists of <INFO_ROW> elements and <TD> child elements. There is an
attribute @SWAP in the <INFO_ROW>  element   either set to 'true' or
'false'. Essentially when  the page loads, my for-each loop checks that SWAP
value; if it is false, only a single table row is written with the NAME
attribute of the <INFO_ROW> element. If the SWAP value is 'true', then the
first table row with the NAME attribute is written, as well as all children
<TD> elements, thus creating an expaned table. These true and false values
are to establish any default preferences. Here is a sampling of that XML:
<CONTENT>
    <INFO_ROW NAME="row1" SWAP="true">
      <TD>This is a condition</TD>
      <TD>This is what condition my condition is in</TD>
      <TD>owww!</TD>
  </INFO_ROW>
  <INFO_ROW NAME="row2" SWAP="true">
      <TD>Row 2...This is another condition</TD>
      <TD>Row 2...This is how my condition is today</TD>
      <TD>Row 2...Hep Me!</TD>
    </INFO_ROW>
</CONTENT>

On each INFO_ROW in the xsl I include a href that passes the INFO_ROW's
@NAME and true or false to hidden form fields and then submit the form. I
submit this to a servlet (xalan,xerces, on tomcat and Apache) and as part of
the dynamic XML generated from the request, the servlet writes out an
<INPUT> tag with the name value pairs as attributes. when the page reloads
it again gets the hard-coded SWAP values, a test is present (it is there
initially as well, just didnt mention it till now) that determines the
default SWAP value (lets say 'true') and sees if there is any 'true' or
'false' values in the dynamically created INPUT tags. If so, then I need to
determine if the INPUT value is different than the INFO_ROW and act
accordingly. Here is my dilemma: Since the INFO_ROW/@NAME is sent as a
name-value pair, when the test is applied i cannot test for a specific NAME
(ie, if test="row1"...), I am in a for-each and I need to say "for this
INFO_ROW, if there is an attrubute in the <INPUT> node that has the same
name as the @NAME in the INFO_ROW, what is its value, and is it different
than the @SWAP  value...

I hope that I have explained this clearly enough for someone to help me out.
Below is some samlpe code:

>From the XSL:
the javascript function:
<script language="javascript">
function growRow(name,swap)
{
var f=document.forms[0].elements;
f[name].value=swap;
document.forms[0].submit();
}
</script>

some of the for-each selection:
<xsl:for-each select="/ROOT/CONTENT/INFO_ROW">
 <table xsl:use-attribute-sets ="basic-table" summary="{@NAME}">
  <xsl:choose>
     ***<xsl:when test="@SWAP='true' and @NAME = /ROOT/STATE/INPUT[@(name of
attribute same as @NAME='true']">***
 <tr>
  <th><a href="javascript:growRow('{@NAME}','false');">--</a></th>
  <th colspan="{count(TD)-1}"><xsl:value-of select="@NAME" />
   <input type="hidden" value="" name="{@NAME}" /></th>
 </tr>
<tr>
  <xsl:for-each select="TD">
  <td><xsl:value-of select="text()" /></td>
  </xsl:for-each>
 </tr>
</xsl:when>
***<xsl:when test="@SWAP='true' and /ROOT/STATE/INPUT[@row1->(this is the
dynamic row) ='false']">***
 <tr>
  <th><a href="javascript:growRow('{@NAME}','true');">+</a></th>
  <th colspan="{count(TD)-1}"><xsl:value-of select="@NAME" />
   <input type="hidden" value="" name="{@NAME}" /></th>
 </tr>
</xsl:when>
... and so on.
the *** is the test in question...
it will work if i hard-code a @NAME value in  the test, but i need to be
dynamic because I wont know how many rows or what their names will be...

sample of the dynamic XML output if growRow('row1','true') is sent:
<STATE >
      <INPUT  DD="fakesite/tab/main_page/leftnav" row1="true" row2="" />
      <PATHINFO  VALUE="/" />
</STATE>

I cannot change the servlet so i need to handle the data in this way. Can
anyone help? Or is there a better way to do this expanding/collapsing menu?
Thanks to anyone who can help me with this!!!
-matthew


 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]