Can I call xsl:number() from diff templates and output continous number

Can I call xsl:number() from diff templates and output continous number

Post by Paul » Sun, 20 Oct 2002 03:53:14



stuck by this counting
I made a function with xsl:number, And I call this
function from different templates, everytime it counts
from 1 again, is it possible that xsl:number function
continue counting base on the result of last call.

Generally I need to output an array from different
templates, with increasing number like array(1),array(2)...
but I have to call from different places/templates.

thanks

Paul.

 
 
 

Can I call xsl:number() from diff templates and output continous number

Post by Marro » Sun, 20 Oct 2002 21:33:39


Hi Paul,

Difficult to how to resolve the issue - without seeing either your XML or
XSL.

But if you are using <xsl:number> to count nodes at different levels but
want the resulting number to be contiguous rather than from 1 each time then

Cheers
Marrow, Microsoft XML MVP
http://www.veryComputer.com/ - home of Xselerator (XSLT IDE and de*)
http://www.veryComputer.com/


Quote:> stuck by this counting
> I made a function with xsl:number, And I call this
> function from different templates, everytime it counts
> from 1 again, is it possible that xsl:number function
> continue counting base on the result of last call.

> Generally I need to output an array from different
> templates, with increasing number like array(1),array(2)...
> but I have to call from different places/templates.

> thanks

> Paul.


 
 
 

Can I call xsl:number() from diff templates and output continous number

Post by Marro » Mon, 21 Oct 2002 23:11:56


Hi Paul,

Again, you're not giving much away here ;)  Help us to help you?

Quote:> Is it possible to have a function/template that can be
> called by different templates, and everytime being called,
> it generates a contiguous number, (the <xsl:number> might
> not be appropriate to use here)

No.  As XSLT is a declarative language it would not be possible to do this
as it would involve re-assigning the value of a variable (which cannot be
done).  Some people might suggest using script within your XSLT (not me!) -
but this again would be wholly unreliable as any script would be expected to
be stateless (and incrementing a counter would involve the remembering of
some state) - this may lead to erroneous results with some XSLT
transformation engines (even that support script - i.e. MSXML4).

This leaves you with two alternatives:-
1) use <xsl:number> or some use of count() to determine the contiguous
number (can't say which might be appropriate without seeing XML and desired
output at least)
2) use recursion

Cheers
Marrow, Microsoft XML MVP
http://www.veryComputer.com/ - home of Xselerator (XSLT IDE and de*)
http://www.veryComputer.com/


> Hi Marrow

> Many thanks for your reply,

> it looks complicated in my case, as I need generate code
> (similar to a data type) from the schema. for example:
> Some schema refer to other type which have enumeration
> values, all these enumeration items need to be counted
> into array also. , and some complexType won't be
> counted ... I think <xsl:number> will bring a lots trouble
> here, as it strictly follow the nodes of the tree

> Is it possible to have a function/template that can be
> called by different templates, and everytime being called,
> it generates a contiguous number, (the <xsl:number> might
> not be appropriate to use here)

> very much appreciate yr kind response in advanced

> Paul

> >-----Original Message-----
> >Hi Paul,

> >Difficult to how to resolve the issue - without seeing
> either your XML or
> >XSL.

> >But if you are using <xsl:number> to count nodes at
> different levels but
> >want the resulting number to be contiguous rather than
> from 1 each time then

> >Cheers
> >Marrow, Microsoft XML MVP
> >http://www.veryComputer.com/ - home of Xselerator (XSLT IDE
> and de*)
> >http://www.veryComputer.com/



> >> stuck by this counting
> >> I made a function with xsl:number, And I call this
> >> function from different templates, everytime it counts
> >> from 1 again, is it possible that xsl:number function
> >> continue counting base on the result of last call.

> >> Generally I need to output an array from different
> >> templates, with increasing number like array(1),array
> (2)...
> >> but I have to call from different places/templates.

> >> thanks

> >> Paul.

> >.

 
 
 

Can I call xsl:number() from diff templates and output continous number

Post by paul » Wed, 23 Oct 2002 01:07:31


Hi Marrow

Thanks for you rreply, Hope this can help you to help me ;)
the Desired result is the Familyarray count from 1 to n
contiguously, as you may noticed
Snoopy-a
Snoopy-c
Snoopy-l
Snoopy-o
are ref to other type so it need to generate array
elements as well

Many thanks your help

Paul.

<!-- beginning of schema ***********************-->
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="cobolTest_1.xsl"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
        <xs:element name="Snoopy-a" type="woodstock"/>
        <xs:element name="Snoopy-b">
                <xs:simpleType>
                        <xs:restriction base="xs:string">
                                <xs:length value="8"/>
                                <xs:pattern value="[0-9]{4}
(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])"/>
                        </xs:restriction>
                </xs:simpleType>
        </xs:element>
        <xs:element name="Snoopy-c" type="woodstock"/>
        <xs:element name="Snoopy-GRP">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element ref="Snoopy-d"
maxOccurs="unbounded"/>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
        <xs:element name="Snoopy-d">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element ref="Snoopy-e"
minOccurs="0"/>
                                <xs:element ref="Snoopy-f"
minOccurs="0"/>
                                <xs:element ref="Snoopy-g"
minOccurs="0"/>
                                <xs:element ref="Snoopy-h"
minOccurs="0"/>
                                <xs:choice>
                                        <xs:element
ref="Snoopy-i" minOccurs="0"/>
                                        <xs:element
ref="Snoopy-j" minOccurs="0"/>
                                </xs:choice>
                                <xs:element ref="Snoopy-k"
minOccurs="0"/>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
        <xs:element name="Snoopy-e">
                <xs:simpleType>
                        <xs:restriction base="xs:string">
                                <xs:enumeration value="P"/>
                                <xs:enumeration value="F"/>
                        </xs:restriction>
                </xs:simpleType>
        </xs:element>
        <xs:element name="Snoopy-f">
                <xs:simpleType>
                        <xs:restriction
base="xs:hexBinary">
                                <xs:length value="8"/>
                        </xs:restriction>
                </xs:simpleType>
        </xs:element>
        <xs:element name="Snoopy-g" type="xs:boolean"/>
        <xs:element name="Snoopy-h" type="xs:string"/>
        <xs:element name="Snoopy-i" type="xs:byte"/>
        <xs:element name="Snoopy-j">
                <xs:simpleType>
                        <xs:restriction base="xs:string">
                                <xs:enumeration value="F"/>
                                <xs:enumeration value="M"/>
                        </xs:restriction>
                </xs:simpleType>
        </xs:element>
        <xs:element name="Snoopy-k">
                <xs:simpleType>
                        <xs:restriction base="xs:string">
                                <xs:length value="9"/>
                                <xs:pattern value="[0-9]
*"/>
                        </xs:restriction>
                </xs:simpleType>
        </xs:element>
        <xs:element name="Snoopy-l" type="woodstock"/>
        <xs:element name="Nancy-a" type="charlieBrown"/>
        <xs:element name="Nancy-b" type="charlieBrown"/>
        <xs:element name="Nancy-c" type="charlieBrown"/>
        <xs:element name="Nancy-d" type="charlieBrown"/>
        <xs:element name="Nancy-e">
                <xs:simpleType>
                        <xs:restriction base="xs:string">
                                <xs:length value="9"/>
                                <xs:pattern value="[0-9]
{9}"/>
                        </xs:restriction>
                </xs:simpleType>
        </xs:element>
        <xs:element name="Snoopy-m">
                <xs:simpleType>
                        <xs:restriction
base="xs:hexBinary">
                                <xs:length value="300"/>
                        </xs:restriction>
                </xs:simpleType>
        </xs:element>
        <xs:element name="Nancy-6">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element ref="Nancy-a"/>
                                <xs:element ref="Nancy-b"/>
                                <xs:element ref="Nancy-c"/>
                                <xs:element ref="Nancy-d"/>
                                <xs:element ref="Nancy-e"/>
                                <xs:element ref="Snoopy-
e"/>
                                <xs:element ref="Snoopy-
GRP"/>
                                <xs:element ref="Snoopy-f"
minOccurs="0"/>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
        <xs:simpleType name="woodstock">
                <xs:restriction base="xs:string">
                        <xs:enumeration value="F"/>
                        <xs:enumeration value="L"/>
                        <xs:enumeration value="E"/>
                        <xs:enumeration value="E"/>
                        <xs:enumeration value="D"/>
                </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="charlieBrown">
                <xs:restriction base="xs:string">
                        <xs:length value="8"/>
                        <xs:pattern value="[0-9]*"/>
                </xs:restriction>
        </xs:simpleType>
        <xs:element name="Snoopy-n">
                <xs:simpleType>
                        <xs:restriction base="xs:string">
                                <xs:length value="40"/>
                        </xs:restriction>
                </xs:simpleType>
        </xs:element>
        <xs:element name="Snoopy-o" type="woodstock"/>
</xs:schema>
<!-- end of schema ********************************-->

<!-- beginning of stylesheet ***********************-->
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="html" indent="no"/>

<xsl:template match="/">
        <xsl:apply-templates select="xs:schema"/>
</xsl:template>

<xsl:template match="xs:schema">
                <xsl:variable
name="flagToTag">ToTag</xsl:variable>
                <xsl:apply-templates select="xs:element">
                                <xsl:with-param
name="flag" select="$flagToTag"/>
                </xsl:apply-templates>
</xsl:template>

<xsl:template match="xs:element">
        <xsl:param name="flag"/>
        <xsl:variable name="elementResult">
                <xsl:value-of select='@name'/>
        </xsl:variable>

        <xsl:apply-templates select="//xs:simpleType">
                <xsl:with-param name="nn" select="@name"/>
                <xsl:with-param name="rr" select="@type"/>
        </xsl:apply-templates>

        <xsl:variable name="eleFlag">
                <xsl:if test="boolean(@type)">
                        <xsl:apply-templates
select="//xs:simpleType">
                                        <xsl:with-param
name="nn" select="@name"/>
                                        <xsl:with-param
name="rr" select="@type"/>
                        </xsl:apply-templates>
                </xsl:if>
        </xsl:variable>

        <xsl:if test="(boolean(string-length($eleFlag)
< 10))">
                        <xsl:value-of select="'MOVE1 '"/>
                        <xsl:value-of
select="($elementResult)" />
                        <xsl:value-of select="' TO
FamilyArray('" />
                        <xsl:number level="any"/>
                        <xsl:value-of select="')'" />
                        <xsl:value-of select="'
'"/>
        </xsl:if>
</xsl:template>

<xsl:template match="xs:simpleType">
        <xsl:param name="nn"/>
        <xsl:param name="rr"/>

        <xsl:if test="boolean($rr)">
                <xsl:if test="@name=$rr">
                        <xsl:apply-templates
select="xs:restriction">
                                <xsl:with-param name="nn"
select="$nn"/>
                        </xsl:apply-templates>
                </xsl:if>
        </xsl:if>

</xsl:template>

<xsl:template match="xs:restriction">
        <xsl:param name="nn"/>
        <xsl:variable name="base" select="@base"/>
        <xsl:if test="$base='xs:string' or
$base='xs:unsignedByte'">
                <xsl:if test="boolean(xs:enumeration)">
                        <xsl:apply-templates
select="xs:enumeration">
                                <xsl:with-param name="nn"
select="$nn"/>
                        </xsl:apply-templates>
                </xsl:if>
        </xsl:if>
</xsl:template>

<xsl:template match="xs:enumeration">
        <xsl:param name="nn"/>
        <!-- when the name is passed in, pass-in value
will be used -->
        <xsl:if test="boolean($nn)">
                <xsl:value-of select="'MOVE5 '"/>
                <xsl:value-of select="$nn"/>
                <xsl:value-of select="'-'"/>
                <xsl:value-of select="position()"/>
                <xsl:value-of select="' TO FamilyArray
('" />
                <xsl:number level="any"/>
                <xsl:value-of select="')'" />
                <xsl:value-of select="'
'"/>
        </xsl:if>
</xsl:template>

</xsl:stylesheet>
<!-- end of stylesheet ***************************-->

 
 
 

Can I call xsl:number() from diff templates and output continous number

Post by Marro » Wed, 23 Oct 2002 02:05:19


Hi Paul,

Quote:> Hope this can help you to help me ;)

Yep, I did kinda ask for that one! :)

I'm assuming it is the number in brackets on the end of each line that you
want to be the contiguous numbering?

Hmmm, I think I'd cop out on this one - as I can't see a straight forward
way of using count() or <xsl:number> (and you are already applying down a
tree so recursion would be horrifically complex - too complex for a Monday
afternoon!).

So my cop out would be to use RTFs (result tree fragments) and process once
into an RTF then iterate through a node-set from that RTF to get the
contiguous number, something like....

== XSL ===========================================
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.veryComputer.com/;
 xmlns:xs="http://www.veryComputer.com/;
 xmlns:msxsl="urn:schemas-microsoft-com:xslt">
  <xsl:output method="html" indent="no"/>

  <xsl:template match="/">
    <xsl:apply-templates select="xs:schema"/>
  </xsl:template>

  <xsl:template match="xs:schema">
    <xsl:variable name="flagToTag">ToTag</xsl:variable>
    <xsl:variable name="rtf-temp">
      <xsl:apply-templates select="xs:element">
        <xsl:with-param name="flag" select="$flagToTag"/>
      </xsl:apply-templates>
    </xsl:variable>
    <xsl:for-each select="msxsl:node-set($rtf-temp)/*">
      <xsl:value-of select="."/>
      <xsl:text> (</xsl:text>
      <xsl:value-of select="position()"/>
      <xsl:text>)&#10;</xsl:text>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="xs:element">
    <xsl:param name="flag"/>
    <xsl:variable name="elementResult">

    </xsl:variable>
    <xsl:apply-templates select="//xs:simpleType">


    </xsl:apply-templates>
    <xsl:variable name="eleFlag">

        <xsl:apply-templates select="//xs:simpleType">


        </xsl:apply-templates>
      </xsl:if>
    </xsl:variable>
    <xsl:if test="(boolean(string-length($eleFlag) &lt; 10))">
      <rtf-temp>
        <xsl:text>MOVE1 </xsl:text>
        <xsl:value-of select="$elementResult"/>
        <xsl:text> TO FamilyArray</xsl:text>
      </rtf-temp>
    </xsl:if>
  </xsl:template>

  <xsl:template match="xs:simpleType">
    <xsl:param name="nn"/>
    <xsl:param name="rr"/>
    <xsl:if test="boolean($rr)">

        <xsl:apply-templates select="xs:restriction">
          <xsl:with-param name="nn" select="$nn"/>
        </xsl:apply-templates>
      </xsl:if>
    </xsl:if>
  </xsl:template>

  <xsl:template match="xs:restriction">
    <xsl:param name="nn"/>

    <xsl:if test="$base='xs:string' or $base='xs:unsignedByte'">
      <xsl:if test="boolean(xs:enumeration)">
        <xsl:apply-templates select="xs:enumeration">
          <xsl:with-param name="nn" select="$nn"/>
        </xsl:apply-templates>
      </xsl:if>
    </xsl:if>
  </xsl:template>

  <xsl:template match="xs:enumeration">
    <xsl:param name="nn"/>
    <!-- when the name is passed in, pass-in value will be used -->
    <xsl:if test="boolean($nn)">
      <rtf-temp>
        <xsl:text>MOVE5 </xsl:text>
        <xsl:value-of select="$nn"/>
        <xsl:text>-</xsl:text>
        <xsl:value-of select="position()"/>
        <xsl:text> TO FamilyArray</xsl:text>
      </rtf-temp>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
== end of XSL ====================================

Notice that I've replaced your static <xsl:value-of>'s with <xsl:text> -
using value-of for explicit, static output isn't very efficient.

Hope this helps
Marrow, Microsoft XML MVP
http://www.veryComputer.com/ - home of Xselerator (XSLT IDE and de*)
http://www.veryComputer.com/

 
 
 

Can I call xsl:number() from diff templates and output continous number

Post by Paul » Wed, 23 Oct 2002 05:01:35


Hi Marrow

Very interesting use of Result Tree Fragment to Node-set
Conversion. Thank you very much for your help

tks

Paul

Quote:>-----Original Message-----
>Hi Paul,

>> Hope this can help you to help me ;)

>Yep, I did kinda ask for that one! :)

>I'm assuming it is the number in brackets on the end of
each line that you
>want to be the contiguous numbering?

>Hmmm, I think I'd cop out on this one - as I can't see a
straight forward
>way of using count() or <xsl:number> (and you are already
applying down a
>tree so recursion would be horrifically complex - too

complex for a Monday
Quote:>afternoon!).

>So my cop out would be to use RTFs (result tree

fragments) and process once

- Show quoted text -

>into an RTF then iterate through a node-set from that RTF
to get the
>contiguous number, something like....

>== XSL ===========================================
><?xml version="1.0" encoding="UTF-8"?>
><xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.veryComputer.com/;
> xmlns:xs="http://www.veryComputer.com/;
> xmlns:msxsl="urn:schemas-microsoft-com:xslt">
>  <xsl:output method="html" indent="no"/>

>  <xsl:template match="/">
>    <xsl:apply-templates select="xs:schema"/>
>  </xsl:template>

>  <xsl:template match="xs:schema">
>    <xsl:variable name="flagToTag">ToTag</xsl:variable>
>    <xsl:variable name="rtf-temp">
>      <xsl:apply-templates select="xs:element">
>        <xsl:with-param name="flag" select="$flagToTag"/>
>      </xsl:apply-templates>
>    </xsl:variable>
>    <xsl:for-each select="msxsl:node-set($rtf-temp)/*">
>      <xsl:value-of select="."/>
>      <xsl:text> (</xsl:text>
>      <xsl:value-of select="position()"/>
>      <xsl:text>)
</xsl:text>
>    </xsl:for-each>
>  </xsl:template>

>  <xsl:template match="xs:element">
>    <xsl:param name="flag"/>
>    <xsl:variable name="elementResult">

>    </xsl:variable>
>    <xsl:apply-templates select="//xs:simpleType">


>    </xsl:apply-templates>
>    <xsl:variable name="eleFlag">

>        <xsl:apply-templates select="//xs:simpleType">


>        </xsl:apply-templates>
>      </xsl:if>
>    </xsl:variable>
>    <xsl:if test="(boolean(string-length($eleFlag) <
10))">
>      <rtf-temp>
>        <xsl:text>MOVE1 </xsl:text>
>        <xsl:value-of select="$elementResult"/>
>        <xsl:text> TO FamilyArray</xsl:text>
>      </rtf-temp>
>    </xsl:if>
>  </xsl:template>

>  <xsl:template match="xs:simpleType">
>    <xsl:param name="nn"/>
>    <xsl:param name="rr"/>
>    <xsl:if test="boolean($rr)">

>        <xsl:apply-templates select="xs:restriction">
>          <xsl:with-param name="nn" select="$nn"/>
>        </xsl:apply-templates>
>      </xsl:if>
>    </xsl:if>
>  </xsl:template>

>  <xsl:template match="xs:restriction">
>    <xsl:param name="nn"/>

>    <xsl:if test="$base='xs:string' or

$base='xs:unsignedByte'">

- Show quoted text -

Quote:>      <xsl:if test="boolean(xs:enumeration)">
>        <xsl:apply-templates select="xs:enumeration">
>          <xsl:with-param name="nn" select="$nn"/>
>        </xsl:apply-templates>
>      </xsl:if>
>    </xsl:if>
>  </xsl:template>

>  <xsl:template match="xs:enumeration">
>    <xsl:param name="nn"/>
>    <!-- when the name is passed in, pass-in value will
be used -->
>    <xsl:if test="boolean($nn)">
>      <rtf-temp>
>        <xsl:text>MOVE5 </xsl:text>
>        <xsl:value-of select="$nn"/>
>        <xsl:text>-</xsl:text>
>        <xsl:value-of select="position()"/>
>        <xsl:text> TO FamilyArray</xsl:text>
>      </rtf-temp>
>    </xsl:if>
>  </xsl:template>
></xsl:stylesheet>
>== end of XSL ====================================

>Notice that I've replaced your static <xsl:value-of>'s
with <xsl:text> -
>using value-of for explicit, static output isn't very
efficient.

>Hope this helps
>Marrow, Microsoft XML MVP
>http://www.veryComputer.com/ - home of Xselerator (XSLT IDE
and de*)
>http://www.veryComputer.com/

>.

 
 
 

1. ><xsl:value-of select="(number(firstNum) - number(thirdNum))div 2 "/>

Hi Everybody!

I am working with ie5.5 including the new xmlsdk. i have been using the
xalan xml parser up do now , but need to use the msxml parser for better
performance. my problem is to convert my current stylesheet to a format
that the msxml parser understands

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

 which is supported by a different parser. What I want to do is use the
values of two different nodes to perform a calculation. I have included
code, but I am having difficulties to get ie5.x to parse the code using
the namespace:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" version="1.0">

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

"xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                                            version="1.0">

 Please advice me how I should go about to achieve a similar result with
the ie5.x parser.

 Thank you.
Bernhard

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- <xsl:template match="/">
<HTML><BODY>
    <TABLE>
        <xsl:for-each select="number">
        <TR>
            <TD><xsl:value-of select="firstNum"/></TD>
            <TD><xsl:value-of select="thirdNum"/></TD>
            <TD><xsl:value-of select="(number(firstNum) -
number(thirdNum))div 2"/></TD>
        </TR>
        </xsl:for-each>
    </TABLE>
</BODY></HTML>
</xsl:template>
</xsl:stylesheet>

2. multithreads and winsock

3. setting xsl:number to start numbers with 0 ?

4. Bit Masks for Interrupts

5. XSLT/XSL-FO: Calling a template without using xsl:call-template

6. FS: Amiga books CHEAP!!!

7. format-number : Displaying numbers like 1.500,34 and 65.124,23

8. Entry not in design list

9. How do I divide a number by the number of nodes in a list?

10. format-number or formatNumber functions and negative numbers

11. format-number and scientific numbers

12. XSL: Line Numbers in output?

13. xsl:apply-templates vs. xsl:call-template