xsl-list
[Top] [All Lists]

Re: [xsl] formatting issues

2006-11-03 13:29:01
Here's what I have so far. Based on the trivial differences in what is 
displayed based on the varying values of "sym", I dispensed with the multiple 
match templates


<xsl:template match="state">
  <xsl:variable name="dyn-data" select="document(...whatever goes in here...)" 
/>

  <xsl:choose>
    <xsl:when test="sym='A'">
      <tr><td colspan="8"><b>STATES: </b></td></tr>
    </xsl:when>
    <xsl:when test="sym='C'">
      <tr><td colspan="8"><b>Contain: </b></td></tr>
    </xsl:when>
    <xsl:when test="sym='R'">
      <tr><td colspan="8"><b>Required: </b></td></tr>
    </xsl:when>
  </xsl:choose>
  <tr>
    <td width="9%"><u>Val1</u></td>
    <td width="15%"><u>Val2</u></td>
    <td width="7%"><u>Val3</u></td>
    <td width="7%"><u>Val4</u></td>
    <td width="9%"><u>Val5</u></td>
    <td width="21%"><u>Val6</u></td>
    <td width="15%"><u>Val7</u></td>
    <td width="7%"><u>Val8</u></td>
  <tr>
    <td><xsl:value-of select="Val1"/></td>
    <td><xsl:value-of select="Val2"/></td>
    <td><xsl:value-of select="Val3"/></td>
    <td><xsl:value-of select="Val4"/></td>
    <xsl:apply-templates select="$dyn-data/results/data" />
  </tr>
  </tr>
</xsl:template>

<xsl:template match="data">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="*[parent::data]">
  <td><xsl:value-of select="." /></td>
</xsl:template>


Let's look at the sample of your dynamic document:

<results>
  <data>
    <Val5>something</Val5>
    <Val6>something</Val6>
    <Val7>something</Val7>
    <Val8>P</Val8>
  </data>
  <data>
    <Val5>something</Val5>
    <Val6>something</Val6>
    <Val7>something</Val7>
    <Val8>P</Val8>
  </data>
</results>

Your template for handling the "state" element showed eight columns. The data 
for columns one through 4 comes from the input document and the other values 
come from the dynamic document. Given eight columns, it seems that you have two 
(or more, given "data> can be any number inside <results>") values in your 
dynamic document for each column in the output document.

Do you want to continue to add <td> elements to the row until all the <data> 
elements in the dynamic document are handled?

If so, what heading do you want for each column?

Will you keep repeating "Val5", "Val6","Val6","Val8" over and over again as the 
column heading?

Do you want to start a new row for each <data> element in the dynamic document?
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     ms <mina_hurray(_at_)yahoo(_dot_)com>
Sent:     Fri, 3 Nov 2006 08:24:31 -0800 (PST)
To:       xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject:  RE: Re: [xsl] formatting issues

Thank you for your response and sorry for the delay.  

Are you saying that there may be "state" elements
with "sym" child elements that contain text nodes
which can have any one of these values "R", "A", and
"C" and further that you want to process each type
differently?

Yes, the sym element can contain "r, a or C" as
values. The only diffrence will be in the heading for
each valye. For example: if sym="R" , then the table
heading should change to "Required", if it is C it
should change to "Contain" , other than that the
content is the same. So when each of the "state"
elements are processed, the "sym" should be cheked in
order to put the right heading and display in
different tables. 

Did you > envision putting the values from one or the
other > set of (Val5, Val6, Val7, Val8) in the row in
the > template above, and if so, how would you
distinguish > which "data" node to use? 

All the "data" elements should be displayed.

--- cknell(_at_)onebox(_dot_)com wrote:

You need to parse the question a little more
carefully.
============================ > "state" elements according to an earlier 
statement
you made, are always and only child elements of
"states". That is to say all "state" elements are
siblings and their parent element is "states".
Therefor the construct "//state" is pointless and a
waste of processing effort since it tells the
processor to find all "state" elements at whatever
level they may be in the source document.

============================ > Are you saying that there may be "state" 
elements
with "sym" child elements that contain text nodes
which can have any one of these values "R", "A", and
"C" and further that you want to process each type
differently?

If so, you will want to create three templates:

<xsl:template match="state[sym='A']>
</xsl:template>

<xsl:template match="state[sym='C']>
</xsl:template>

<xsl:template match="state[sym='R']>
</xsl:template>

and inside each template, put the content you want
each to output.

So at some point you will have a template like this:

<xsl:template match="states">
  <xsl:apply-templates />
</xsl:template>

which will cause every "state" element to be
processed by it's distinct template.
============================ > 
Since you have shown in some detail what you want to
output when you encounter a "state" element with a
"sym" child with a value of "R", let's consider what
that template would look like.

<xsl:template match="state[sym='R']>
  <tr><td colspan="8"><b>STATES: </b></td></tr>
  <tr>
    <td width="9%"><u>Val1</u></td>
    <td width="15%"><u>Val2</u></td>
    <td width="7%"><u>Val3</u></td>
    <td width="7%"><u>Val4</u></td>
    <td width="9%"><u>Val5</u></td>
    <td width="21%"><u>Val6</u></td>
    <td width="15%"><u>Val7</u></td>
    <td width="7%"><u>Val8</u></td>
  <tr>
    <td><xsl:value-of select="Val1"/></td>
    <td><xsl:value-of select="Val2"/></td>
    <td><xsl:value-of select="Val3"/></td>
    <td><xsl:value-of select="Val4"/></td>
    .... We'll deal with the dynamically-generated
data here ....
  </tr>
  </tr>
</xsl:template>

On the subject of the dynamically-generated data,
I'm going to suggest you put it in a variable to
make things easier for me to work with, so we are
going to modify the template above to this:

<xsl:template match="state[sym='R']>
  <xsl:variable name="dyn-data" select="document(...
whatever goes in here...)" />
  <tr><td colspan="8"><b>STATES: </b></td></tr>
  <tr>
    <td width="9%"><u>Val1</u></td>
    <td width="15%"><u>Val2</u></td>
    <td width="7%"><u>Val3</u></td>
    <td width="7%"><u>Val4</u></td>
    <td width="9%"><u>Val5</u></td>
    <td width="21%"><u>Val6</u></td>
    <td width="15%"><u>Val7</u></td>
    <td width="7%"><u>Val8</u></td>
  <tr>
    <td><xsl:value-of select="Val1"/></td>
    <td><xsl:value-of select="Val2"/></td>
    <td><xsl:value-of select="Val3"/></td>
    <td><xsl:value-of select="Val4"/></td>
    ... Questions about dynamic data still to be
answered ...
  </tr>
  </tr>
</xsl:template>

You showed a sample of the document that would be
returned by the document() function. It contained a
root node of "results" that had two "data" child
nodes. You showed in your original stylesheet an
intent to insert the content of the dynamic document
here. Each of the two "data" nodes had an identical
set of child nodes (Val5, Val6, Val7, Val8). Did you
envision putting the values from one or the other
set of (Val5, Val6, Val7, Val8) in the row in the
template above, and if so, how would you distinguish
which "data" node to use? If you planned to use both
(or all, if there are more than two "data" nodes")
do you intend to add additional columns to this row
or to break the output into several rows?
============================ > 
Let's have the answers to these questions before we
go any further.
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     ms <mina_hurray(_at_)yahoo(_dot_)com>
Sent:     Thu, 2 Nov 2006 08:43:32 -0800 (PST)
To:       xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject:  Re: [xsl] formatting issues

Thank you very much for your interest and response.
Here is my response:

 >Your test tries to establish if there is any "sym"
element with a value of 
"R" that is a child of a "state" element that my
be
at any level in the 
document. If so then it goes on to create a
table.

Is that really what you want to do?

- Yes, the 'sym' element can have values R, A and C.
So depending on the value of sym, the heading for
the
table changes. I have done a similar code for the
other values also. 






From: cknell(_at_)onebox(_dot_)com
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: RE: Re: [xsl] formatting issues
Date: Thu, 02 Nov 2006 10:18:25 -0500

I'm willing to work with you on this, but the
XSLT
you showed is such an 
awful mess that in order for me to spend time on
the problem, we'll have to 
clean it up no matter that "So hetting these to
display correctly on the 
XSLT is not an issue."

Based on what I see in your stylesheet, I surmise
that you are fairly new 
to XSLT, or at least, you haven't had the benefit
of training by someone 
with a good understanding of the processing
model.

So let's start with your first template. I'll
quote
from the first part:

<xsl:template match="states">
  <br/>
  <xsl:if test="//state/sym='R'">

Your test tries to establish if there is any
"sym"
element with a value of 
"R" that is a child of a "state" element that my
be
at any level in the 
document. If so then it goes on to create a
table.

Is that really what you want to do? Since you say
that all "state" elements 
are children of one "states" element, there is no
point in starting the 
test attribute value with two slashes. You could
accomplish the same thing, 
with less confusion and at less processing cost
by
replacing your construct 

=== message truncated == 


 
____________________________________________________________________________________
Cheap Talk? Check out Yahoo! Messenger's low PC-to-Phone call rates 
(http://voice.yahoo.com)


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--