Using elements within elements---how to extract correctly?

Using elements within elements---how to extract correctly?

Post by Kathy Burk » Thu, 03 Apr 2003 05:29:54



Hi, me again. First, I am still TRYING to learn more...currently reading
Mastering XSLT by Chuck White...but I still haven't figured out how to
do this:

BriefExample of XML Source (nested steps with 2 other POSSIBLE elements
as needed--checkbox and measure (they would initially be EMPTY when
parsed to the user:

<process_step>
<step><checkbox></checkbox><para>This is step one of this work
instruction.</para>
<step><para>This is the first substep of step one.</para>
</step>
<step><para>This is the second substep of step one.</para>
<step><para>This is the first substep of 1.2.</para>
</step>
</step>
</step>
<step><checkbox></checkbox><para>This is step two of the work
instruction.</para>
<step><para>This is the first substep of step two.</para>
<measure></measure></step>
<step><para>This is the second substep of step two.</para>
</step>
<step><para>For authoring, we would need to adjust the EIC in the FOSI.
For
XSLT transforms, this nested step process should be the simplest to
maintain
and use.</para>
</step>
</step>
<step><para>Step 3 and last step.</para>
</step>
</process_step>

From past help from Dimitre, I know how to get the numbered steps, but
PLEASE tell me how to tranform this xml to this html (I do know HTML,
just not the XML part):

Column 1        Column 2
---------------------------------------------------
Checkbox        1. Step one.
---------------------------------------------------
                   1.1 step.
---------------------------------------------------
Measure            1.2 step.
---------------------------------------------------
Checkbox           1.3 step.
---------------------------------------------------
etc.

So, simply put(?), I'm trying to parse this into a 2 column html table
with nested steps indented.

And please point me to an example of formatting this out into an html
table...please! I know it has something to do with xsl:value-of
select="" but I haven't figured out the correct way from examples I've
seen.

As always, thanks for the guidance. I can certainly see the power
possible with xslt...but it's killing me trying to learn it...too routed
in the relational database mode perhaps.

Kathy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

Using elements within elements---how to extract correctly?

Post by L. Adrian Jackso » Sat, 05 Apr 2003 05:23:25


Well it aint pritty but then neither am I. Do I get a no-prize?

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
        <xsl:template match="process_step">
                <table border="1">
                        <xsl:apply-templates select="step"/>
                </table>
        </xsl:template>
        <xsl:template match="step">
                <xsl:param name="stepno"/>
                <xsl:variable name="_stepno">
                        <xsl:value-of select="$stepno"/>
                        <xsl:if test="$stepno">.</xsl:if>
                        <xsl:value-of select="position()"/>
                </xsl:variable>
                <tr>
                        <td>
                                <xsl:if test="checkbox">
                                                checkbox html here
                                        </xsl:if>
                                <xsl:if test="measure">
                                         measure html here
                                        </xsl:if>
                        </td>
                        <td>
                                <xsl:value-of select="$_stepno"/> -
<xsl:value-of select="./para"/>
                        </td>
                </tr>
                <xsl:if test="descendant::step">
                        <xsl:apply-templates select="step">
                                <xsl:with-param name="stepno">
                                        <xsl:value-of
select="$_stepno"/>
                                </xsl:with-param>
                        </xsl:apply-templates>
                </xsl:if>
        </xsl:template>
</xsl:stylesheet>

It needs a lot of work obviously but theres the basics to get you
going. G'Luck



Quote:>Hi, me again. First, I am still TRYING to learn more...currently reading
><snip>
>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it!

Regards

Lee

--------------------------------------------------------------------------------
I need a job!! If you're a London, UK based company
and have a suitable project/position for a VERY
experienced developer, please contact me at

--------------------------------------------------------------------------------

 
 
 

Using elements within elements---how to extract correctly?

Post by Kathy Burk » Sat, 05 Apr 2003 06:19:57


Thank you so much Lee! I think I actually understand SOME of it too!

May I be greedy? Could you please tell me how I would handle other
elements within the step element? For example, there will be hrefs, note
(format), etc. Do I do a template for each of the possible elements,
then refer to them within the HTML body? Quick example?

Happy Thursday...

KathyBurke

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

Using elements within elements---how to extract correctly?

Post by Kathy Burk » Sat, 05 Apr 2003 06:19:58


Hi again,

In reading your very lovely answer, I can't quite understand what this
part is doing. (1) assigns a parameter to step named "stepno", then...?

<xsl:param name="stepno"/>
        <xsl:variable name="_stepno">
            <xsl:value-of select="$stepno"/>
            <xsl:if test="$stepno">.</xsl:if>
            <xsl:value-of select="position()"/>

Any illumination appreciated!
KathyBurke

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

Using elements within elements---how to extract correctly?

Post by L. Adrian Jackso » Sun, 06 Apr 2003 04:28:43


All it is is the equivilent of how you use <xsl:number> - it
constructs the numeric step in a much more roundabout fashion (I didnt
even know xsl:number could do that - learn something new etc )



Quote:>Hi again,

>In reading your very lovely answer, I can't quite understand what this
>part is doing. (1) assigns a parameter to step named "stepno", then...?

><xsl:param name="stepno"/>
>        <xsl:variable name="_stepno">
>            <xsl:value-of select="$stepno"/>
>            <xsl:if test="$stepno">.</xsl:if>
>            <xsl:value-of select="position()"/>

>Any illumination appreciated!
>KathyBurke

>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it!

Regards

Lee

--------------------------------------------------------------------------------
I need a job!! If you're a London, UK based company
and have a suitable project/position for a VERY
experienced developer, please contact me at

--------------------------------------------------------------------------------

 
 
 

Using elements within elements---how to extract correctly?

Post by L. Adrian Jackso » Sun, 06 Apr 2003 04:32:49


The example I posted handles the document in a programatic manner - to
handle other elements use <xsl:apply-templates select="whatever"/> as
needed. You may need to use the above several times to construct the
document as you need.



Quote:>Thank you so much Lee! I think I actually understand SOME of it too!

>May I be greedy? Could you please tell me how I would handle other
>elements within the step element? For example, there will be hrefs, note
>(format), etc. Do I do a template for each of the possible elements,
>then refer to them within the HTML body? Quick example?

>Happy Thursday...

>KathyBurke

>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it!

Regards

Lee

--------------------------------------------------------------------------------
I need a job!! If you're a London, UK based company
and have a suitable project/position for a VERY
experienced developer, please contact me at

--------------------------------------------------------------------------------

 
 
 

1. "Big Picture" question on output/format of elements within elements using xslt

Hope I can explain my question clearly...

Say I have an XML document which contains several elements. One of
those elements named <step> can contain <para>, <list>, etc. It can
also contain tags such as <emphasis>, <link>, <checkbox_complete>,
<measurement> etc. (with attribute IDs, etc.)

The <step> element can nest into various levels (using xsl:number to
output an outline numbering scheme).

The "vision" is to have an html table format, pulling the checkbox
and/or measurement elements (if existing) into the first column, and
the numbered step into the second column. And, of course, applying
typcial hmtl code to apply styles (e.g., emphasis = bold). Any given
row may be just an indented substep (1.1.2) -- does that matter? Is
this possible?

There would be hundreds of xml documents using this stylesheet
(step-by-step instructions) so I would need some flexibility vs.
having to write an xslt instance specifying unique IDs etc. for each
document.

QUESTION: Is this possible -- without putting the whole thing into
.net or something and parsing it out "database" style?

If it is, could you please give me some ideas on what to look for? Any
guidance appreciated...I have read loads of books and group postings
but haven't seen anything addressing this (at least that I
recognized!).

TIA,

KathyBurke

2. What do i look for in a cdr-drive?

3. #PCDATA and element within an element?

4. Viva 14.4 vs. Comp. City 14.4 WOW!

5. XML to HTML: How to format elements within another element?

6. Need Info on KBSE 94

7. Element within an element

8. postgresql 6.5.1

9. How to create CDATA section within a xsl:element created element?

10. Element nested within text of parent element.

11. XSD Schema - generic "let this element have only sub-elements, but *any* sub-element"

12. Sorting elements then removing a child element of a sorted element

13. XALAN: using cdata-section-elements with elements having prefixes - Bug?