xsl-list
[Top] [All Lists]

[xsl] Re: Sort XML based on Tokenized String of sort by field

2008-05-29 08:54:08
Michael,

If you try something and it doesn't work, then by far the best way of
getting help is to tell us exactly what you did and exactly what
happened >as a result; we'll then usually be able to tell you what you
did wrong and >(provided we know what you were trying to achieve) how to
put it right.

(I've no idea what you mean by "a variable tag", but if you showed us
some >code, it would be self-evident).

Sorry, I will clarify better.

I created a stylesheet that will produce the stylesheet that I am
looking for. It still needs enhancements for the data type but for now
it is something like this-

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
        version="2.0" xmlns:saxon="http://saxon.sf.net/";>
        
 <xsl:variable name="PATH" select="REPORT/REPORT_FORMAT/PARENT_NODE"/>
 <xsl:variable name="ORDER_BY" select="REPORT/REPORT_FORMAT/ORDER_BY"/>
 <xsl:variable name="ORDER_BY_TOKEN"
select="tokenize($ORDER_BY,'\s*,\s*')"/>
        
 <xsl:strip-space elements="*"/>

 <xsl:output indent="yes"/>

 <xsl:template match="/">
   <xsl:element name="xsl:transform">
        <xsl:attribute name="version" select="'2.0'"/>
          <xsl:element name="xsl:template">
        <xsl:attribute name="match" select="concat('REPORT/',$PATH)"/>
                 <xsl:element name="xsl:copy">
                <xsl:element name="xsl:for-each">
                <xsl:attribute name="select" select="'*'"/>
        
        <xsl:for-each select="$ORDER_BY_TOKEN">
         <xsl:variable name="ORDER">
            <xsl:choose>
                <xsl:when test="contains(normalize-space(.), 'DES')">
                        <xsl:text>descending</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                        <xsl:text>ascending</xsl:text>
                </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:variable name="VALUE">
          <xsl:choose>
                <xsl:when test="contains(normalize-space(.), ' DES')">
                 <xsl:value-of
select="substring-before(normalize-space(.), ' ')"/>
                </xsl:when>
        <xsl:otherwise>
         <xsl:value-of select="normalize-space(.)"/>
        </xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:element name="xsl:sort">
        <xsl:attribute name="select" select="$VALUE"/>
                <xsl:attribute name="order" select="$ORDER"/>
                </xsl:element>
        </xsl:for-each>
        <xsl:element name="xsl:copy-of">
        <xsl:attribute name="select" select="'.'"/>
                                                </xsl:element>
                                        </xsl:element>
                                </xsl:element>
                        </xsl:element>
                        <xsl:element name="xsl:template">
                                <xsl:attribute name="match"
select="'*'"/>
                                <xsl:element name="xsl:copy">
                                        <xsl:element
name="xsl:apply-templates"/>
                                </xsl:element>
                        </xsl:element>
                </xsl:element>
                </xsl:template>
</xsl:stylesheet>

 In my java code, if I do two passes and transform the xml first with
this stylesheet and then again with the stylesshet resulting from the
first transformation, that works perfectly.

In his post David mentioned being able to do this in one pass using the
saxon:transform extension. I have not been able to figure out how to do
this...

He says " you can do that in one call to saxon, if you wish with the
saxon-transform extension, which means that the generated stylesheet can
just be ina variable and never actually serialised."

I tried to create a variable to hold this stylesheet but when I output
the variable - it is empty. 

Like I try


<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
        version="2.0" xmlns:saxon="http://saxon.sf.net/";>
        
 <xsl:variable name="PATH" select="REPORT/REPORT_FORMAT/PARENT_NODE"/>
 <xsl:variable name="ORDER_BY" select="REPORT/REPORT_FORMAT/ORDER_BY"/>
 <xsl:variable name="ORDER_BY_TOKEN"
select="tokenize($ORDER_BY,'\s*,\s*')"/>
        
 <xsl:strip-space elements="*"/>

 <xsl:output indent="yes"/>

 <xsl:template match="/">
        <xsl:variable name="NEW_STYLESHEET"
           <xsl:element name="xsl:transform">
                ....
           </xsl:element>
        </xsl:variable>
        <xsl:value-of select="$NEW_STYLESHEET"/>
</xsl:template>
</xsl:stylesheet>

I want to somehow store the stylesheet and then call something like
<xsl:copy-of select="saxon:transform($NEW_STYLESHEET,/)"/>  if that
would work...

Thanks so much.
- Rebecca



Merlin Securities - #1 Prime Broker North America and #1 Prime Broker Single 
Strategy Funds - Global Custodian 2007
#1 Prime Broker for Hedge Funds under $1 Billion - Alpha Survey 2007



 
--------------------------------------------------------------------------
This message contains information from Merlin Securities, LLC, or from one of 
its affiliates, that may be confidential and privileged. If you are not an 
intended recipient, please refrain from any disclosure, copying, distribution 
or use of this information and note that such actions are prohibited. If you 
have received this transmission in error, please notify the sender immediately 
by telephone or by replying to this transmission.
 
Merlin Securities, LLC is a registered broker-dealer. Services offered through 
Merlin Securities, LLC are not insured by the FDIC or any other Federal 
Government Agency, are not deposits of or guaranteed by Merlin Securities, LLC 
and may lose value. Nothing in this communication shall constitute a 
solicitation or recommendation to buy or sell a particular security.



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