[Top] [All Lists]

Re: [xsl] modify output document elements

2020-03-05 02:44:02
Well, many things...

First, using named templates is often a bad practise. You'd better use templates with patterns, it makes the stylesheet more readable, more maintenable, and it allows to process source in many steps.

If you want modify your generated table, the best thing to do is to reprocess it :

<xsl:mode name="tableModif" on-no-match="shallow-copy"/>
  <xsl:variable name="firstStep" as="element(table)">
    <table border="0" cellspacing="0">
      <!-- your whole table code here -->
  <xsl:apply-templates select="$firstStep" mode="tableModif"/>

<xsl:template match="th" mode="tableModif">
    <xsl:attribute name="style">font-weight: bold;</xsl:attribute>
    <xsl:apply-templates select="node()|@*"/>

Here two things : when table element is generated, it is kept into a variable, and does not do to output. Then, I re-process the variable (that contains a table element) in a user-defined mode, call tableModif ; in that mode, when there is no specific template that match an item, item is copied. And I declare a template that is activated for each th element in mode tableModif, and this template  copies the template element, adds a style attribute, and continue to process each attributes and each child elements of th - there are copied, because of xsl:mode definition, and because there is no specific tempalte rule.

Hope this helps,

Le 04/03/2020 à 18:49, Kammering, Raimund raimund(_dot_)kammering(_at_)desy(_dot_)de a écrit :

I have a stylesheet which creates a HTML output document dynamically based on 
the incoming XML file. I use some for-each loop to get the processing done in 
the right order. My layout causes the stylesheet to look like this:

   <xsl:template name="details_table">
     <table border="0" cellspacing="0">
         <td width="64px">
           <a href="#" onclick="toggle('{$details_table}')" title="show/hide 
             <img src="show_hide.png"/>
       <table id="{$details_table}" cellspacing="3" style="display: block">
           <td width="64px">
             <img border="0" src="{$imagedir}/null.gif"/>
           <th align="left">Start</th>
           <th align="left">End</th>
           <th align="left">Duration [h]</th>
           <th align="left">Type</th>
           <th align="left">Category</th>
           <th align="left">Comment</th>
<xsl:for-each select="entry[severity='STATISTICS']/statistics_category">
             <xsl:when test=".='Down'">
               <td width="150" valign="top">
                   <xsl:when test="../Down='not_set'">
                      <font color="red">not_set</font>
                      <xsl:value-of select="../Down"/>

Now I would like to modify the style of the details_table depending on the 
outcome of the test within the for-each loop. Since the table element has 
already been created, I do not know how one could do this without changing the 
overall logic. Is there a way to access the elements of the created HTML DOM 
tree from within the stylesheet? Or am I hunting in the wrong direction?!

Any ideas/help welcome - greetings,
Raimund Kammering

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com

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