xsl-list
[Top] [All Lists]

Re: Repeated Recursion on different parts of a tree

2002-09-30 05:58:24


Hello,

Is there anyway I can perform the below operation by 
'calling' a template by name, instead of using a template 
match?

 <xsl:template match="register">
  ... <xsl:apply-templates select="bitfield[1]"/>....
 
 
 with
 <xsl:template match="bitfield">
   <xsl:param  ... whatever parameters you need .../>
     ... some sums ...
   <xsl:apply-templates 
select="following-sibling::bitfield[1]">
    <xsl:with-param ... new values passed to the next
   </xsl:apply-templates>
 ...


My XML looks like:

<register name="DATA" offset="0">
    <no_of_regs>1</no_of_regs>
    <descriptivename>Data register</descriptivename>
    <description>The ...ster.</description>
    <description>In ord..H.</description>
    <description>..Oe...</description>
    <bitfield name="DATA">
      <function>Input data.</function>
      <bitpos>0</bitpos>
      <no_of_bits>10</no_of_bits>
      <initialvalue>0</initialvalue>
      <accesstype>R</accesstype>
    </bitfield>
    <bitfield name="CONTROL">
      <function>Output data</function>
      <bitpos>10</bitpos>
      <no_of_bits>6</no_of_bits>
      <initialvalue>0</initialvalue>
      <accesstype>RW</accesstype>
    </bitfield>
etc..........

</register>

<register name="SWAP" offset="10">
    <no_of_regs..........

(I want to use values in each bitfield to create an 
expression for the whole <register> e.g output document to 
look like - Register DATA initialValue = X......) 

My existing XSL stylesheet already has a few templates 
which are called 'by name'. So when I implement the above,
I an getting junk in my output document. (actually I seem 
to get the source xml element value output for each first
<bitfield> element)

Therefore I would like to call the template by name so as 
not to incur these side effects. Any ideas?


Thankyou


PD





On Thu, 26 Sep 2002 13:00:20 +0100 David Carlisle 
<davidc(_at_)nag(_dot_)co(_dot_)uk> wrote:


cant dynamically update a variable in XSL while traversing the tree.

you just need to make your variable a parameter to your template and 
pass on the parameter at the same time as traversing the tree.
You;ll probably want to traverse th etree one at a time rather than
applying templates to a set of sibling nodes at the same time as that
helps keep ones notion of paremeter passing and template invocation in
sync.

that is, instead of doing

<xsl:template match="register">
 ... <xsl:apply-templates select="bitfield"/>....

do


<xsl:template match="register">
 ... <xsl:apply-templates select="bitfield[1]"/>....


with
<xsl:template match="bitfield">
  <xsl:param  ... whatever parameters you need .../>
    ... some sums ...
  <xsl:apply-templates select="following-sibling::bitfield[1]">
   <xsl:with-param ... new values passed to the next
  </xsl:apply-templates>
...

David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

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


----------------------
Peter Doggett
ee99ppd(_at_)brunel(_dot_)ac(_dot_)uk


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