xsl-list
[Top] [All Lists]

Re: [xsl] Weired Result of XSLT

2007-05-22 01:55:38
Yes!!! after a lot of R&D which have been suggested by this list, the conclusion seems that below is the safe and best:
<xsl:template match="contrib-group">
<contributors>
<xsl:apply-templates select="contrib"/>
</contributors>
</xsl:template>

Thanks once again!!!
...JSR

At 09:43 AM 5/22/2007 +0100, you wrote:
On 5/22/07, J. S. Rawat <jrawat(_at_)aptaracorp(_dot_)com> wrote:
Lot of thanks for your nice clue !!! I have written <xsl:strip-space
elements="*"/> and it is working fine.

That's fine if you XML is data-centric, but if you have mixed content
nodes (document-centric) then you may be stripping significant
whitespace.

An alternative approach is to only select the nodes you want to
process, eg replace:

<xsl:template match="contrib-group">
 <contributors>
   <xsl:apply-templates/>
  </contributors>
</xsl:template>


<xsl:template match="contrib-group">
 <contributors>
   <xsl:apply-templates select="contrib"/>
  </contributors>
</xsl:template>

Then position() will work as expected.

Another alternatively is to replace position() with
count(preceding-sibling::contrib) which will only count <contrib>
elements, ignoring the whitespace presentational nodes between each
element.

Another alternative is to control the flow differently -
apply-templates to the first <contrib> element and output markup
specific to the first, then apply-templates to the rest.  This is
achieved easily with a mode, eg:

<xsl:template match="contrib-group">
 <contributors>
   <xsl:apply-templates select="contrib[1]" mode="first"/>
  </contributors>
</xsl:template>

<xsl:template match="contrib" mode="first">
 <person_name sequence="first" contributor_role="author">
   <xsl:apply-templates select="name"/>
 </person_name>

 <xsl:apply-templates select="following-sibling::contrib"/>
</xsl:template>

<xsl:template match="contrib">
 <person_name sequence="additional" contributor_role="author">
   <xsl:apply-templates select="name"/>
 </person_name>
</xsl:template>

However as both variations are identical other than the @sequence then
I'd just use an AVT, eg.

sequence="{if (not(preceding-sibling::contrib)) then 'first' else 'additional'}"

cheers
andrew


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

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