how to re-arrange the value of an XML element while displaying

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ram1979
    New Member
    • Mar 2010
    • 1

    how to re-arrange the value of an XML element while displaying

    XML
    -----
    Code:
    <vdu vdu_id="4b8febcd000000000a5901f2232f0002"> 
    <field><name>vdu_id</name><value>4b8febcd000000000a5901f2232f0002</value></field> 
    <Field><Name>ANI</Name><Value></Value> 
    </Field> 
    <Field><Name>AccountNumber</Name><Value></Value> 
    </Field> 
    <Field><Name>ERMCaseCategory</Name><Value></Value> 
    </Field> 
    <Field><Name>ERMCaseId</Name><Value></Value> 
    </Field>
    <Field><Name>extradata</Name><Value></Value> 
    <Container count="6"> 
    <Field><Name>emailtype</Name><Value>NOR</Value> 
    </Field> 
    <Field><Name>messageId</Name><Value>589</Value> 
    </Field> 
    <Field><Name>tenantLogoURL</Name><Value></Value> 
    </Field> 
    <Field><Name>tenant_key</Name><Value>2</Value> 
    </Field> 
    <Field><Name>tenantname</Name><Value>IMLGTenant</Value> 
    </Field> 
    <Field><Name>trackingNumber</Name><Value>T201003040002</Value> 
    </Field> 
    </Container> 
    </Field> 
    </vdu>
    XSL
    -----

    Code:
    <HTML>
    <HEAD>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
    <TITLE>eDU Viewer</TITLE>
    </HEAD>
    <BODY STYLE="border: 0px; margin: 0px; font-family: arial; font-style: bold;font-size: 10pt">
    <xsl:for-each select="vdu">
    <TABLE BORDER="1" CELLSPACING="1" CELLPADDING="1" STYLE="border:0px; margin: 0px; 
    font-family: arial; font-style: bold;font-size: 8pt">
    <xsl:for-each select="Field[not(Container or IndexedContainer)]">
    <xsl:apply-templates/>
    </xsl:for-each>
    
    <xsl:for-each select="Field[Container or IndexedContainer]">
    <xsl:choose>
    <xsl:when test="Name[. = 'customerInfo']">
    <TR><TD bgcolor="yellow" align="center" colspan = "2"><B>Customer Information</B></TD></TR>
    <xsl:apply-templates/>
    </xsl:when>
    <!-- Put list of top level containers that should be displayed -->
    <!-- nested containers require additional customization -->
    <xsl:when test="yellow[. = 'xxContainerNamexx']">
    <TR><TD bgcolor="red" align="center" colspan="2"><B>xx Container Name xx</B></TD></TR>
    <xsl:apply-templates/>
    </xsl:when>
    </xsl:choose>
    </xsl:for-each>
    </TABLE>
    </xsl:for-each>
    </BODY>
    </HTML>
    </xsl:template>
    
    <xsl:template match="Field[not(Container or IndexedContainer)]/Name">
    <xsl:apply-templates select="Field/Name[. = 'ERMCaseId']"/>
    <xsl:apply-templates select="Field/Name[. = 'AccountNumber']"/>
    <xsl:apply-templates select="Field/Name[. = 'ERMCaseCategory']"/>
    </xsl:template>
    
    <xsl:template match="Field/Name[. = 'ERMCaseId']">
    <xsl:if test="../Name[. = 'ERMCaseId']"><TR><TD><TH ALIGN="left">ERM CASE ID</TH></TD><TD><xsl:value-of select="../Value"/></TD></TR></xsl:if>
    </xsl:template>
    
    <xsl:template match="Field/Name[. = 'AccountNumber']">
    <xsl:if test="../Name[. = 'AccountNumber']"><TR><TD><TH ALIGN="left">ACCOUNT NUMBER</TH></TD><TD><xsl:value-of select="../Value"/></TD></TR></xsl:if>
    </xsl:template>
    
    <xsl:template match="Field/Name[. = 'ERMCaseCategory']">
    <xsl:if test="../Name[. = 'ERMCaseCategory']"><TR><TD><TH ALIGN="left">ERM CASE CATEGORY</TH></TD><TD><xsl:value-of select="../Value"/></TD></TR></xsl:if> 
    </xsl:template>

    I want to display in this order

    ERM CASE ID
    ACCOUNT NUMBER
    ERM CASE CATEGORY

    but my display comes in the order of source xml file

    ACCOUNT NUMBER
    ERM CASE CATEGORY
    ERM CASE ID
    Last edited by Dormilich; Mar 7 '10, 04:58 PM. Reason: Please use [code] tags when posting code
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Use select="."
    Code:
    <xsl:for-each select="Field[not(Container or IndexedContainer)]"> 
      <xsl:apply-templates select="."/> 
    </xsl:for-each>
    Last edited by jkmyoung; Mar 8 '10, 02:15 PM. Reason: originally misinterpreted question

    Comment

    Working...