0

Did research here sort via xpath and here Grouping using the Münchian Method but couldn't find how to adapt for my situation sort on 'fieldValue' for 'Label' inside 'userField[23]', inside 'SysStructure_FIELD[146]'

This is my xslt:

 <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
   <xsl:strip-space elements="*" /> 
   <xsl:output method="xml" indent="yes" /> 
   <xsl:template match="/Root/STRUCTURESet/STRUCTURE/userField[2]/STRUCTURE_Fields/SysStructure_FIELD">
      <xsl:copy> 
         <xsl:apply-templates select="objectId"/>
            <xsl:apply-templates select="userField">
            <xsl:sort select="fieldLabel[10]/fieldValue" data-type="text" order="ascending"/>
         </xsl:apply-templates>
      </xsl:copy>
   </xsl:template>
   <xsl:template match="@*|node()">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
</xsl:stylesheet> 

The desired output: to have the fieldValue's Labels sorted is not achieved. Can you help out?

xml in shortened form is below ( 'userField(3)', inside 'SysStructure_FIELD(3)' ) :

<Root version="1-1">
<STRUCTURESet>
    <STRUCTURE id="STRUCTURE_0">
        <objectId class="STRUCTURE">
            <identifier>49</identifier>
            <primarySystem>Sys</primarySystem>
            <label>Sys_Default_Structure</label>
        </objectId>
        <userField>
            <fieldLabel>Description</fieldLabel>
            <fieldValue>Sys Default structure level</fieldValue>
            <fieldType>character</fieldType>
        </userField>
        <userField>
            <fieldLabel>Fields</fieldLabel>
            <STRUCTURE_Fields>
                <SysStructure_FIELD>
                    <objectId class="SysStructure_FIELD">
                        <primarySystem>Sys</primarySystem>
                    </objectId>
                    <userField>
                        <fieldLabel>Hide</fieldLabel>
                        <fieldValue>0</fieldValue>
                        <fieldType>numeric</fieldType>
                    </userField>
                    <userField>
                        <fieldLabel>Label</fieldLabel>
                        <fieldValue>System_value</fieldValue>
                        <fieldType>character</fieldType>
                    </userField>
                    <userField>
                        <fieldLabel>MainReturn</fieldLabel>
                        <fieldValue/>
                        <fieldType>character</fieldType>
                    </userField>
                </SysStructure_FIELD>
                <SysStructure_FIELD>
                    <objectId class="SysStructure_FIELD">
                        <primarySystem>Sys</primarySystem>
                    </objectId>
                    <userField>
                        <fieldLabel>Hide</fieldLabel>
                        <fieldValue>0</fieldValue>
                        <fieldType>numeric</fieldType>
                    </userField>
                    <userField>
                        <fieldLabel>Label</fieldLabel>
                        <fieldValue>Off_Market</fieldValue>
                        <fieldType>character</fieldType>
                    </userField>
                    <userField>
                        <fieldLabel>MainReturn</fieldLabel>
                        <fieldValue/>
                        <fieldType>character</fieldType>
                    </userField>
                </SysStructure_FIELD>
                <SysStructure_FIELD>
                    <objectId class="SysStructure_FIELD">
                        <primarySystem>Sys</primarySystem>
                    </objectId>
                    <userField>
                        <fieldLabel>Hide</fieldLabel>
                        <fieldValue>0</fieldValue>
                        <fieldType>numeric</fieldType>
                    </userField>
                    <userField>
                        <fieldLabel>Label</fieldLabel>
                        <fieldValue>System_Time</fieldValue>
                        <fieldType>character</fieldType>
                    </userField>
                    <userField>
                        <fieldLabel>MainReturn</fieldLabel>
                        <fieldValue/>
                        <fieldType>character</fieldType>
                    </userField>
                </SysStructure_FIELD>
            </STRUCTURE_Fields>
        </userField>
        <userField>
            <fieldLabel>Label</fieldLabel>
            <fieldValue>Sys_Default_Structure</fieldValue>
            <fieldType>character</fieldType>
        </userField>
    </STRUCTURE>
</STRUCTURESet>

LeoS
  • 15
  • 5
  • Could you please edit the question and share the input XML? It is not possible to identify the problem looking at the XSLT and the desired output. – Aniket V Jul 27 '18 at 04:16
  • in the [screenprint] (https://i.stack.imgur.com/palPw.jpg) you see the issue I'm facing: want to sort on the fieldValue. The complete xml is >30000 lines, therefore only a part of the xml is added in this case, This XML has 3 values to be sorted. System_Value, Off_Market and System_Time. – LeoS Jul 27 '18 at 08:26
  • With help of a friendly colleague the issue is fixed. This is the change to be done to get it to work: – LeoS Jul 30 '18 at 13:09
  • If the issue has been fixed, you can add the solution yourself. In future it will be helpful for others who stumble upon this question. Also the question would move out from the "Unanswered" list of questions. – Aniket V Jul 31 '18 at 04:20

1 Answers1

0

Because in the structure there is twice a userField is mentioned, you need to specify exactly what field you want to examine: userField/fieldLabel[text()='Label' instead of userField/fieldLabel[10] Furthermore you need to sort on the same level as the fieldLabel: ../fieldValue is doing the job.

So complete statement is:

    <xsl:template match="/Root/STRUCTURESet/STRUCTURE/userField[2]/STRUCTURE_Fields"> 
<xsl:copy> 
<xsl:apply-templates select="SysStructure_FIELD"> 
<xsl:sort select="userField/fieldLabel[text()='Label']/../fieldValue" /> 
</xsl:apply-templates>
LeoS
  • 15
  • 5