Re: [xsl] copy of specific elements

Subject: Re: [xsl] copy of specific elements
From: henry human <henry_human@xxxxxxxx>
Date: Mon, 18 Aug 2008 18:35:18 +0200 (CEST)
The senario is like this:
The user choose from the User interface different html
elements(inputfield, paragraph, image, etc.) This
elemets are placeholder for author name, author
birthday, author age, author etc, author etc )
Each time he puts information, the elements are stored
in the XML file as <element type=author>, <element
type=authr-name>, etc
(These are about 30 attributes for a author)
Having finished the first author, th user put
information for the next author.
At the end the user put section elements which are
indicator for the XSL file, that how many sections it
has to have. A section is a html table with 10 rows
and 5 colums. Inside these tables are the information
about each author saved. We can say the section
element is no imporrtant it is only the indicator and
could be a number like 2, 3, etc.

When the xsl file is called to generate the output ,
it read the section number than generate the identical
tables and put the informationaccording to their
position inside of the xml file.
Let say if the xml file had had an index it could be
like this:

<elements>
<elsment type=author-name>   /* position 1 */
<elsment type=author-age>    /* position 2 */ 
<elsment type=author-whatEver>   /* position 3 */ 
<elsment type=author-whatelse>    /* position 4 */
<elsment type=author-importanThing>    /* position 5
*/
.......      /* position 6 */
........... 
....
........ /* position 100 */
<elsment type=section>
<elsment type=section>


<elements>

Output: 
Now the XSL file should managed the assembly of these
information insid of html tables:

<table id=1>
<tr><td><xsl:value-of
select="document/elements/element[@type='author-name'][1]"/></td></tr>
<tr><td><xsl:value-of
select="document/elements/element[@type='author-age'][2]"/></td></tr>
<tr><td><xsl:value-of
select="document/elements/element[@type='author-whatEver'][3]"/></td></tr>

<tr><td> <xsl:value-of
select="document/elements/element[@type='author-
importanThing '][4]"/></</td></tr>
<hr>

</table>


<table id=2>
<tr><td><xsl:value-of
select="document/elements/element[@type='author-name'][5]"/></td></tr>
<tr><td><xsl:value-of
select="document/elements/element[@type='author-age'][6]"/></td></tr>
<tr><td><xsl:value-of
select="document/elements/element[@type='author-whatEver'][7]"/></td></tr>

<tr><td> <xsl:value-of
select="document/elements/element[@type='author-
importanThing '][8]"/></</td></tr>
<hr>
</table>


<table id=25>

.


With a template I can not assemble the information
inside of tables, because the position of the
elements are different and they should be organized in
different positions. Because of that I try to do it
with a for-each loop.
I hope you understand me now better.
Thank you for your cotributions.





--- Norman Gray <norman@xxxxxxxxxxxxxxx> schrieb:

> 
> Greetings.
> 
> On 2008 Aug 18, at 14:21, henry human wrote:
> 
> > I tried with the FAQ and i understood it so as i
> am
> > witing the code snippet bellow!
> > Here is the sample.
> > In this loop it should turns 2 times because there
> are
> > 2 sections and than displays the
> > author names in:
> > author[1] and
> > author[2]
> > (this is the array: [@type='author'][position()])
> 
> This account doesn't really match what the sample
> XSLT is trying to  
> do, but I think I understand what you're after. 
> Consider the following:
> 
> % cat hh.xml
> <document>
>    <elements>
>      <element type="author">Author number
> 1</element>
>      <element type="author">Author number
> 2</element>
>      <element type="section">section 1</element>
>      <element type="section">section 2</element>
>    </elements>
> </document>
> % cat hh.xslt
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
>                 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>    <xsl:output method="html"/>
>    <xsl:template match="/">
>      <html>
>        <body>
>          <xsl:apply-templates
>             
>
select='document/elements/element[@type="section"]'/>
>        </body>
>      </html>
>    </xsl:template>
>    <xsl:template match='element'>
>      <p>Element: <xsl:apply-templates/></p>
>    </xsl:template>
> </xsl:stylesheet>
> % xsltproc hh.xslt hh.xml
> <html><body>
> <p>Element: section 1</p>
> <p>Element: section 2</p>
> </body></html>
> %
> 
> (Did you want something to happen to the <author>
> elements?  It's not  
> at all clear)
> 
> I think that your fundamental problem is that you're
> thinking of  
> 'arrays' and 'indexes' in a language where this
> isn't natural.  You  
> probably don't need to use position() at all.
> 
> In XSL, using for-each is almost always the wrong
> (or at least an  
> unnatural) way of doing things.  Of course, 'wrong'
> here is a bit of  
> an exaggeration, but it does seem to be true that
> the people who use  
> xsl:for-each the most are those new to the language.
> 
> XSL is a templating language, specialised for
> processing trees of  
> elements, and that means that implicit loop within
> the xsl:apply- 
> templates is usually the most suited to the job.
> 
> Best wishes,
> 
> Norman
> 
> 
> -- 
> Norman Gray  :  http://nxg.me.uk
> Physics and Astronomy, University of Leicester
> 
> 


__________________________________________________
Do You Yahoo!?
Sie sind Spam leid? Yahoo! Mail verf|gt |ber einen herausragenden Schutz gegen Massenmails. 
http://mail.yahoo.com 

Current Thread