xsl-list
[Top] [All Lists]

Re: [xsl] writing out of the current boundary of an element

2006-11-20 04:13:28
On 11/19/06, Nima Kaviani <nkaviani(_at_)sfu(_dot_)ca> wrote:
Hi,

I need to write an element outside the boundary of the "current()"
element which is being written to the output file.

for example having the output below written by my XSLT and considering
that I am filling the values inside the inner, I need to write another
element, as a child of <test:Base>, but based on the values I obtain
while I am writing the inner element:

<test:Base>
<test:Rule>
<test:Inner>
  ####
</test:Inner>
</test:Rule>
</test:Base>

so I need the output to be like this:

<test:Base>
<!--------------The new part-------------------->
<test:newlyAdded>
     *********
</test:newlyAdded>

<test:Rule>
<test:Inner>
  ####
</test:Inner>
</test:Rule>
</test:Base>

Add this template to a basic identity transform:

<xsl:template match="test:Base">
 <test:newlyAdded>
     *********
 </test:newlyAdded>
 <xsl:apply-templates/>
</xsl:template>

This will produce exactly what your example result file shows.

If you need the <test:newlyAdded> element to be different depending on
the contents of <test:base>, then you can use predicates, eg:

<xsl:template match="test:Base[test:Rule/test:Inner = 'xyz']">
 <test:newlyAdded>xyz</test:newlyAdded>
 <xsl:apply-templates/>
</xsl:template>

...then add templates for each "rule".

The problem here is your question and examples are pretty
underspecified, eg you say "based on the values I obtain" but don't
show the values or what output should correspond to what value...

--~------------------------------------------------------------------
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>
--~--