|
Subject: Re: [xsl] sorting (again) From: "Davis Ford" <davisford@xxxxxxxxx> Date: Thu, 29 Nov 2007 12:43:38 -0500 |
Thanks all...this list is a huge help!
Incidentally, the last two you proposed do work, Scott. The first
does not. I've updated the template as follows:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:copy-of select="@*"/>
<!-- copy all attributes before applying templates to children only -->
<xsl:apply-templates select="node()">
<!--<xsl:sort select="- number(name() = 'DictionaryModelDescriptor')"/>-->
<xsl:sort select="- boolean(self::DictionaryModelDescriptor)"/>
<xsl:sort select="@typeName"/>
<xsl:sort select="name(.)"/>
<xsl:sort />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
On Nov 29, 2007 12:36 PM, Scott Trenda <Scott.Trenda@xxxxxxxx> wrote:
> Hey Davis,
>
> The reason that your first try isn't working is because <xsl:sort
> select="DictionaryModelDescriptor"/> looks down the child:: axis for an
> element named "DictionaryModelDescriptor", when you actually want it to
> look down the self:: axis for that element. I think any of the following
> would work (you'll have to try them out):
>
> <xsl:sort select="self::DictionaryModelDescriptor"/>
> <xsl:sort select="- number(name() = 'DictionaryModelDescriptor')"/>
> <xsl:sort select="- boolean(self::DictionaryModelDescriptor)"/>
>
> The unary negop is there to avoid specifying order="descending"; I'm not
> quite sure if the last two would need data-type="number" or not. There
> may be other shortcuts that work more concisely, and these may need some
> tweaking to work just right. Be sure to let us know what worked the best
> in the end, ok?
>
> ~ Scott
>
>
>
> -----Original Message-----
> From: Davis Ford [mailto:davisford@xxxxxxxxx]
> Sent: Thursday, November 29, 2007 11:10 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] sorting (again)
>
> Hi, one more sorting question.
>
> Given the XML pasted below...I'm using the following transform to sort
> it canonically. However, I need the "DictionaryModelDescriptor" node
> to always be the first node, and then the rest are sorted canonically.
> I tried this, but it does not do what I want.
>
> <xsl:template match="@*|node()">
> <xsl:copy>
> <xsl:apply-templates select="@*|node()">
> <xsl:sort select="DictionaryModelDescriptor"/>
> <xsl:sort select="@typeName"/>
> <xsl:sort select="name(.)"/>
> <xsl:sort />
> </xsl:apply-templates>
> </xsl:copy>
> </xsl:template>
>
> This one puts it at the top, but now I have a duplicate in the middle
>
> <xsl:template match="@*|node()">
> <xsl:copy>
> <xsl:apply-templates select="DictionaryModelDescriptor"/>
> <xsl:apply-templates select="@*|node()">
> <xsl:sort select="@typeName"/>
> <xsl:sort select="name(.)"/>
> <xsl:sort />
> </xsl:apply-templates>
> </xsl:copy>
> </xsl:template>
> How can I "move" the DictionaryModelDescriptor node to the top after
> sorting?
>
> Thanks in advance,
> Davis
>
> XML ->
>
> <?xml version="1.0" encoding="UTF-8"?>
> <DictionaryModel>
> <DictionaryModelDescriptor about="modelName1/modelVersion1">
> <modelName>modelName1</modelName>
> <modelVersion>modelVersion1</modelVersion>
> </DictionaryModelDescriptor>
> <DictionaryParts>
> <DictionaryPart abstract="false" typeName="part.full1">
> <children/>
> <parents/>
> <DictionaryProperties/>
> <feature>feature.empty3</feature>
> <maxCardinality>2</maxCardinality>
> <minCardinality>1</minCardinality>
> <parentComposition>feature.empty2</parentComposition>
> <role>role</role>
> <sequence>1</sequence>
> </DictionaryPart>
> <DictionaryPart abstract="false" typeName="part.full5">
> <children/>
> <parents/>
> <DictionaryProperties/>
> <feature>feature.empty13</feature>
> <maxCardinality>2</maxCardinality>
> <minCardinality>1</minCardinality>
> <parentComposition>feature.empty12</parentComposition>
> <role>role</role>
> <sequence>1</sequence>
> </DictionaryPart>
> </DictionaryParts>
> <DictionaryAssociations>
> <DictionaryAssociation abstract="false"
> typeName="association.empty1">
> <children/>
> <parents/>
> <DictionaryProperties/>
> </DictionaryAssociation>
> <DictionaryAssociation
> compositionType="BIDIRECTIONAL_ASSOCIATION" abstract="false"
> typeName="association.full2">
> <children/>
> <parents/>
> <DictionaryProperties>
>
> <DictionaryProperty>simple.property.empty4</DictionaryProperty>
>
> <DictionaryProperty>composite.property.empty4</DictionaryProperty>
> </DictionaryProperties>
> <sourcePart>part.full2</sourcePart>
> <targetPart>part.full3</targetPart>
> <resolverStrategy>resolver.strategy</resolverStrategy>
> </DictionaryAssociation>
> </DictionaryAssociations>
> <DictionaryFeatures>
> <DictionaryFeature composite="false" abstract="false"
> typeName="feature.empty1">
> <children/>
> <parents/>
> <DictionaryProperties/>
> <associations/>
> <parentComposites/>
> <parts/>
> </DictionaryFeature>
> <DictionaryFeature composite="true" compositionType="SEQUENCE"
> abstract="true" typeName="feature.full8">
> <children>
> <child>feature.empty9</child>
> </children>
> <parents/>
> <DictionaryProperties>
>
> <DictionaryProperty>composite.property.empty5</DictionaryProperty>
>
> <DictionaryProperty>simple.property.empty5</DictionaryProperty>
> </DictionaryProperties>
> <associations>
> <association>association.empty3</association>
> <association>association.empty4</association>
> </associations>
> <parentComposites>
> <parentComposite>feature.empty10</parentComposite>
> </parentComposites>
> <parts>
> <part>part.empty4</part>
> </parts>
> <code>code</code>
> </DictionaryFeature>
> </DictionaryFeatures>
> <DictionaryPropertyNodes>
> <DictionaryPropertyNode abstract="false"
> typeName="property.node.empty1">
> <children/>
> <parents/>
> <DictionaryProperties/>
> </DictionaryPropertyNode>
> <DictionaryPropertyNode abstract="false"
> typeName="property.node.full3">
> <children>
> <child>property.node.empty4</child>
> </children>
> <parents>
> <parent>property.node.empty5</parent>
> </parents>
> <DictionaryProperties>
>
> <DictionaryProperty>composite.property.empty11</DictionaryProperty>
>
> <DictionaryProperty>simple.property.empty8</DictionaryProperty>
> </DictionaryProperties>
> </DictionaryPropertyNode>
> </DictionaryPropertyNodes>
> <DictionaryProperties>
> <DictionaryProperty
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="CompositeDictionaryProperty" propertyType="COMPOSITE_ROOT"
> inherited="false" typeName="composite.property.empty1">
> <maxCardinality>2147483647</maxCardinality>
> <minCardinality>-2147483648</minCardinality>
> <children/>
> </DictionaryProperty>
> <DictionaryProperty
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="CompositeDictionaryProperty" propertyType="COMPOSITE_ROOT"
> inherited="false" typeName="composite.property.empty2">
> <maxCardinality>2147483647</maxCardinality>
> <minCardinality>-2147483648</minCardinality>
> <children/>
> </DictionaryProperty>
> <DictionaryProperty
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="CompositeDictionaryProperty" propertyType="COMPOSITE_ROOT"
> inherited="false" typeName="composite.property.empty3">
> <maxCardinality>2147483647</maxCardinality>
> <minCardinality>-2147483648</minCardinality>
> <children/>
> </DictionaryProperty>
> <DictionaryProperty
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="CompositeDictionaryProperty" propertyType="COMPOSITE_CHILD"
> inherited="true" typeName="composite.property.full6">
> <code>code</code>
> <maxCardinality>3</maxCardinality>
> <minCardinality>2</minCardinality>
> <parentObject>feature.empty14</parentObject>
> <parentProperty>composite.property.empty8</parentProperty>
> <rootProperty>composite.property.empty7</rootProperty>
> <children>
> <child>simple.property.empty6</child>
> </children>
> <propertyNode>property.node.empty2</propertyNode>
> </DictionaryProperty>
> <DictionaryProperty
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="SimpleDictionaryProperty" propertyType="SIMPLE_ROOT"
> inherited="false" typeName="simple.property.empty1">
> <maxCardinality>2147483647</maxCardinality>
> <minCardinality>-2147483648</minCardinality>
> </DictionaryProperty>
> <DictionaryProperty
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="SimpleDictionaryProperty" propertyType="SIMPLE_ROOT"
> inherited="false" typeName="simple.property.empty2">
> <maxCardinality>2147483647</maxCardinality>
> <minCardinality>-2147483648</minCardinality>
> </DictionaryProperty>
> <DictionaryProperty
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="SimpleDictionaryProperty" propertyType="SIMPLE_ROOT"
> inherited="false" typeName="simple.property.empty3">
> <maxCardinality>2147483647</maxCardinality>
> <minCardinality>-2147483648</minCardinality>
> </DictionaryProperty>
> <DictionaryProperty
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="SimpleDictionaryProperty" propertyType="SIMPLE_CHILD"
> inherited="true" typeName="simple.property.full7">
> <code>code</code>
> <maxCardinality>2</maxCardinality>
> <minCardinality>1</minCardinality>
> <parentObject>feature.empty16</parentObject>
> <parentProperty>composite.property.empty9</parentProperty>
> <rootProperty>composite.property.empty10</rootProperty>
> <defaultValue>default-value</defaultValue>
>
> <dictionaryFeatureRange>feature.range2</dictionaryFeatureRange>
> <referentFeature>feature.empty17</referentFeature>
> <dictionaryValueRange>value.range1</dictionaryValueRange>
> <valueTypeName>value-type-name</valueTypeName>
> </DictionaryProperty>
> </DictionaryProperties>
> <DictionaryFeatureRanges>
> <DictionaryFeatureRange typeName="feature.range1">
> <DictionaryFeatures>
> <DictionaryFeature>feature.empty11</DictionaryFeature>
> </DictionaryFeatures>
> </DictionaryFeatureRange>
> </DictionaryFeatureRanges>
> <DictionaryValueRanges>
> <DictionaryValueRange typeName="value.range2">
> <DictionaryRangeItems>
> <DictionaryRangeItem>range.item3</DictionaryRangeItem>
> </DictionaryRangeItems>
> <valueTypeName>value-type-name</valueTypeName>
> </DictionaryValueRange>
> </DictionaryValueRanges>
> <DictionaryRangeItems>
> <DictionaryRangeItem typeName="range.item2">
> <value>4</value>
> </DictionaryRangeItem>
> </DictionaryRangeItems>
> <DictionaryValueTypeNames>
> <DictionaryValueTypeName>a value type
> name</DictionaryValueTypeName>
>
> <DictionaryValueTypeName>value-type-name</DictionaryValueTypeName>
> </DictionaryValueTypeNames>
> </DictionaryModel>
>
>
--
Zeno Consulting, Inc.
http://www.zenoconsulting.biz
248.894.4922 phone
313.884.2977 fax
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] sorting (again), Scott Trenda | Thread | RE: [xsl] sorting (again), Michael Kay |
| RE: [xsl] sorting (again), Michael Kay | Date | Re: [xsl] recursive sorting by elem, Davis Ford |
| Month |