[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Defining variables as sequence of strings

Subject: Re: Defining variables as sequence of strings
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 14 May 2015 18:26:28 -0000
Re:  Defining variables as sequence of strings
Joseph,

> One question though, in my effort to refactor and avoid the for-each
>
> constructs, how do you output the results of the sequence contained
>
> within $vTypes utilizing some type formatting while inside a perform-sort.
>
> For example, I want each element on a line of its own, contained within
>
> some other text:
>
>
>
> ......Some other text (a) More text....
>
> ......Some other text (b) More text....
>
> ......Some other text (c) More text....
>

Depending on the particular "formatting task" this can be done in
different ways -- even using <xsl:foreach>

Here is a simple example that can replace the sorting code in the
previous solution and that produces your wanted output:

    <xsl:variable name="vSorted" as="xs:string*">
     <xsl:perform-sort select="distinct-values($vTypes)">
      <xsl:sort select="."/>
     </xsl:perform-sort>
     </xsl:variable>

     <xsl:value-of select=
      "$vSorted/concat('...Some other text (', ., ') More Text....')"
separator="&#xD;&#xA;"/>


So, the complete transformation in this case is:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xsl:output method="text"/>
  <xsl:template match="/*">
    <xsl:variable name="vTypes" as="xs:string*">
      <xsl:apply-templates select="*/@type"/>
    </xsl:variable>
    <xsl:variable name="vSorted" as="xs:string*">
     <xsl:perform-sort select="distinct-values($vTypes)">
      <xsl:sort select="."/>
     </xsl:perform-sort>
     </xsl:variable>

     <xsl:value-of select=
      "$vSorted/concat('...Some other text (', ., ') More Text....')"
separator="&#xD;&#xA;"/>
  </xsl:template>
  <xsl:template match="property/@type[. eq 'foo']">
    <xsl:sequence select="'a', 'b'"/>
  </xsl:template>
  <xsl:template match="property/@type[. = ('bar', 'baz', 'bof')]">
    <xsl:sequence select="'b', 'c'"/>
  </xsl:template>
  <xsl:template match="property/@type" priority="-1">
   <xsl:sequence select="'c', 'd'"/>
  </xsl:template>
 </xsl:stylesheet>


and when applied on the same XML document:

<object>
   <property name="name" type="foo"/>
   <property name="key" type="bar"/>
   <property name="size" type="baz"/>
   <property name="age" type="bof"/>
   <property name="grade" type="goo"/>
 </object>

it produces the wanted result:

...Some other text (a) More Text....
...Some other text (b) More Text....
...Some other text (c) More Text....
...Some other text (d) More Text....

Instead of the function concat(), you may call an xsl:function that
you have written yourself, that could perform more subtle formatting.


Cheers,
Dimitre




-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.