Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


transpose with logic

From: "Jazper Manto" <ejazper@-------.--->
To: NULL
Date: 3/31/2005 8:35:00 PM
hi
i'm very new to xslt and have the task to transpose one structure into
another. i already found solutions on the net but could not get it to work
with my problem:

Source XML:As you can see is that i have 3 records in xml but only 2 logical
ones because a record is defined over its ID.
---
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Record>
    <ID>1</ID>
    <Name>criteria1</Name>
    <Value>44</Value>
  </Record>
  <Record>
    <ID>1</ID>
    <Name>criteria2</Name>
    <Value>1920</Value>
  </Record>
  <Record>
    <ID>3</ID>
    <Name>criteria3</Name>
    <Value>98</Value>
  </Record>
  <Record>
    <ID>7</ID>
    <Name>criteria2</Name>
    <Value>18</Value>
  </Record>
</NewDataSet>

Target XML: my xslt should now be able to sum that like this. i must concat
these 3 xml records into 2 logical xml records.
---
<?xml version="1.0" standalone="yes"?>
<RecordCollection>
  <Record>
    <ID>1</ID>
    <C1>44</C1>
    <C2>1920</C2>
    <C3>98</C3>
  </Record>
  <Record>
    <ID>7</ID>
    <C2>18</C2>
  </Record>
</RecordCollection>

My Solution: here is my solution which is not working because i really don't
know how to go on now...
---
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:transform xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version =
"1.0" xmlns:xs = "http://www.w3.org/2001/XMLSchema">
 <xsl:template match = "/">
  <RecordCollection>
   <xsl:for-each select = "NewDataSet/Record">
    <xsl:variable name = "iOuterId" select = "ID"/>
    <Record>
     <xsl:apply-templates select = "ID"/>
     <xsl:apply-templates select = "XCoordinate"/>
     <xsl:for-each select = "/NewDataSet/Record">
      <xsl:variable name = "iInnerID" select = "ID"/>
      <xsl:variable name = "strCriteria" select = "Name"/>
      <xsl:if test="$iInnerID = $iOuterId">
       <xsl:choose>
        <xsl:when test="$strCriteria = 'criteria1'">
         <C1>
          <xsl:value-of select = "Value"/>
         </C1>
        </xsl:when>
        <xsl:when test="$strCriteria = 'criteria2'">
         <C2>
          <xsl:value-of select = "Value"/>
         </C2>
        </xsl:when>
        <xsl:when test="$strCriteria = 'criteria2'">
         <C2>
          <xsl:value-of select = "Value"/>
         </C2>
        </xsl:when>
       </xsl:choose>
      </xsl:if>
     </xsl:for-each>
    </Record>
   </xsl:for-each>
  </RecordCollection>
 </xsl:template>
 <xsl:template match = "ID">
  <xsl:element name = "ID">
   <xsl:value-of select = "."/>
  </xsl:element>
 </xsl:template>
 <xsl:template match = "Value">
  <xsl:element name = "X">
   <xsl:value-of select = "."/>
  </xsl:element>
 </xsl:template>
</xsl:transform>

is there anybody out there in the crule xml world who can help my solution
to fix?
thank you very much
jazper




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent