This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Position X Sort-> Please urgent!


Paulo,

At 03:35 PM 9/27/01, you wrote:
>But this can't occur ever.
>This example my xmloriginal and my xmladd are in order, but in cases they
>aren't.
>I think that I would need get a position in a original formate of xml
>(without consider the sort).

That's right. position() is no help for this. As you figured out, it gives 
the position of the node you are processing within the list of nodes you 
are processing. That's not what you want (but it is a FAQ).

What you want can probably be most easily achieved by doing just what you 
had, except changing your variable declaration to say

<xsl:variable name="var_pos" select="count(preceding-sibling::TEST)+1"/>

which gets you the number of the TEST element among its TEST siblings.

You could also do

<xsl:variable name="var_pos">
   <xsl:number count="TEST" level="single"/>
</xsl:variable>

which would get you the same thing, or even

<xsl:variable name="var_pos">
   <xsl:number/>
</xsl:variable>

(because the defaults for xsl:number are to count the current node's 
element type with level="single")

But users concerned about speed usually go for the first solution because 
<xsl:number> can be slow.

Hope that helps,
Wendell

> > I'm with problems with my transformation and I need to give
> > my project in next week, and need to make others things.
> > Well... I've 2 xml documents and 1 xsl document. The first
> > doc xml (XMLORIGINAL.XML) The second xml document
> > (XMLADD.XML) have informations about first document. The
> > relashion this elements is for position, but I need to print
> > this context using the sort, and I'm having problems with
> > this. Exists a formal of to get a position of element in
> > original formate? My example:
> >
> > <!-- XMLORIGINAL.XML -->
> > <?xml-stylesheet type="text/xsl" href="XSLORIGINAL.XSL"?> <ORIGINAL>
> >   <TEST>1</TEST>
> >   <TEST>2</TEST>
> >   <TEST>3</TEST>
> >   <TEST>4</TEST>
> >   <TEST>5</TEST>
> > </ORIGINAL>
> >
> >
> > <!-- XMLADD.XML -->
> > <ADDS>
> >   <ADD>A</ADD> <!-- This element if referent the 1º <TEST> element -->
> >   <ADD>B</ADD> <!-- This element if referent the 2º <TEST> element -->
> >   <ADD>C</ADD> <!-- This element if referent the 3º <TEST> element -->
> >   <ADD>D</ADD> <!-- This element if referent the 4º <TEST> element -->
> >   <ADD>E</ADD> <!-- This element if referent the 5º <TEST>
> > element --> </ADDS>
> >
> > <!-- XSLORIGINAL.XSL -->
> > <xsl:template match="ORIGINAL">
> >    <xsl:for-each select="TEST">
> >       <xsl:sort select="." data-type="number" order="descending"/>
> >           <xsl:value-of select="."/>
> >           <xsl:variable name="var_pos" select="position()"/>
> >           <xsl:value-of
> > select="document('XMLADD.XML')/ADDS/ADD[$var_pos]">
> >    </xsl:for-each>
> > </xsl:template>
> >
> >
> > I need to print so:
> > ------------------
> > 5E
> > 4D
> > 3C
> > 2B
> > 1A
> >
> > And my result is:
> > ------------------
> > 5A
> > 4B
> > 3C
> > 2D
> > 1E
> >
> > If I can't to print so, then exist another form????
> >
> >
> > Thanks all,
> >
> >
> > Paulo.
> >
> >
> >  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> >
> >
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


======================================================================
Wendell Piez                            mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
   Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]