[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Cosmetic sorting
On 12/29/06, Harry Liljestrom <harry.liljestrom@xxxxxxxxxxxxx> wrote:
Hi, If I understand what should be the result you're after, then this transformation: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <!-- Global variables --> <xsl:variable name="vDg" select="'0123456789 '"/> <xsl:variable name="rule-order"> <xsl:value-of select="normalize-space(/policy-rules/fw-rule-order)"/> </xsl:variable> <xsl:variable name="vnruleOrder" select="translate($rule-order, translate($rule-order, $vDg,''), '')" /> <xsl:template match="policy-rules"> <policy> <xsl:apply-templates select="fw-rules/rule"> <xsl:sort data-type="number" select= "string-length( substring-before($vnruleOrder, translate(@name, translate(@name, $vDg,''), '' ) ) )" /> </xsl:apply-templates> </policy> </xsl:template> <xsl:template match="fw-rules/rule"> <xsl:variable name="vInDir" select= "self::*[direction = 'in']"/> <rule type="{action}"> <src> <xsl:apply-templates select= "remote[$vInDir] | local[not($vInDir)]"/> </src> <dst> <xsl:apply-templates select= "local[$vInDir] | remote[not($vInDir)]"/> </dst> </rule> </xsl:template> <xsl:template match="local | remote"> <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet> when applied on the provided xml document (corrected to be well-formed): <policy-rules> <fw-rule-order> fwrule3 fwrule1 fwrule2 </fw-rule-order> <fw-rules> <rule name="fwrule1"> <direction>out</direction> <action>pass</action> <remote>192.168.129.31</remote> <local>192.168.129.67</local> </rule> <rule name="fwrule2"> <direction>in</direction> <action>drop</action> <remote>192.168.129.32</remote> <local>192.168.129.67</local> </rule> <rule name="fwrule3"> <direction>out</direction> <action>pass</action> <remote>192.168.129.33</remote> <local>192.168.129.67</local> </rule> </fw-rules> </policy-rules> produces the wanted result: <policy> <rule type="pass"> <src>192.168.129.67</src> <dst>192.168.129.33</dst> </rule> <rule type="pass"> <src>192.168.129.67</src> <dst>192.168.129.31</dst> </rule> <rule type="drop"> <src>192.168.129.32</src> <dst>192.168.129.67</dst> </rule> </policy> Hope this helped. -- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|