XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
andrei dadsaSubject: xml problem
Author: andrei dadsa
Date: 08 Aug 2007 01:01 PM
This is an example about what I'm trying to do.

here is my xml file:

<BODY_TYPES>
<BODY_TYPE Name="BT3">
<SCENARIOS>
<SCENARIO Name="SC4" Services="SEARCH" Used="true">
<SCENARIO_STEP_LIST>
<SCENARIO_STEP
Antenna_Area_Definition="DIAGNOSIS_RIGHT_DOOR_AREA"
Number_Of_Error_Retry="2"
Number_Of_Retry="2" Step_Number="FS_LEARN_SK"/>
<SCENARIO_STEP
Antenna_Area_Definition="DIAGNOSIS_BLUMPER_AREA"
Number_Of_Error_Retry="1"
Number_Of_Retry="1" Step_Number="FS_DISCHARGE_MODE"/>
</SCENARIO_STEP_LIST>
<FINISH_STEP_LIST/>
</SCENARIO>
<SCENARIO Name="SC3" Services="" Used="false">
<SCENARIO_STEP_LIST>
<SCENARIO_STEP Antenna_Area_Definition=" "
Number_Of_Error_Retry="0"
Number_Of_Retry="0" Step_Number=" "/>
</SCENARIO_STEP_LIST>
<FINISH_STEP_LIST/>
</SCENARIO>
<SCENARIO Name="SC2" Services="" Used="false">
<SCENARIO_STEP_LIST>
<SCENARIO_STEP Antenna_Area_Definition=" "
Number_Of_Error_Retry="0"
Number_Of_Retry="0" Step_Number=" "/>
</SCENARIO_STEP_LIST>
<FINISH_STEP_LIST/>
</SCENARIO>
<SCENARIO Name="SC1" Services="SEARCH" Used="true">
<SCENARIO_STEP_LIST>
<SCENARIO_STEP
Antenna_Area_Definition="DIAGNOSIS_RIGHT_DOOR_AREA"
Number_Of_Error_Retry="0"
Number_Of_Retry="0" Step_Number="FS_ACCESS_AUTHENTICATION"/>
</SCENARIO_STEP_LIST>
<FINISH_STEP_LIST/>
</SCENARIO>
</SCENARIOS>
</BODY_TYPE>
<BODY_TYPE Name="BT2">
<SCENARIOS>
<SCENARIO Name="SC4" Services="" Used="false">
<SCENARIO_STEP_LIST>
<SCENARIO_STEP Antenna_Area_Definition=" "
Number_Of_Error_Retry="0"
Number_Of_Retry="0" Step_Number=" "/>
</SCENARIO_STEP_LIST>
<FINISH_STEP_LIST/>
</SCENARIO>
<SCENARIO Name="SC3" Services="SEARCH" Used="true">
<SCENARIO_STEP_LIST>
<SCENARIO_STEP
Antenna_Area_Definition="DIAGNOSIS_RIGHT_DOOR_AREA"
Number_Of_Error_Retry="0"
Number_Of_Retry="0" Step_Number="FS_ACCESS_AUTHENTICATION"/>
</SCENARIO_STEP_LIST>
<FINISH_STEP_LIST/>
</SCENARIO>
<SCENARIO Name="SC2" Services="" Used="false">
<SCENARIO_STEP_LIST>
<SCENARIO_STEP Antenna_Area_Definition=" "
Number_Of_Error_Retry="0"
Number_Of_Retry="0" Step_Number=" "/>
</SCENARIO_STEP_LIST>
<FINISH_STEP_LIST/>
</SCENARIO>
<SCENARIO Name="SC1" Services="" Used="false">
<SCENARIO_STEP_LIST>
<SCENARIO_STEP Antenna_Area_Definition=" "
Number_Of_Error_Retry="0"
Number_Of_Retry="0" Step_Number=" "/>
</SCENARIO_STEP_LIST>
<FINISH_STEP_LIST/>
</SCENARIO>
</SCENARIOS>
</BODY_TYPE>
<BODY_TYPE Name="BT1">
<SCENARIOS>
<SCENARIO Name="SC4" Services="" Used="false">
<SCENARIO_STEP_LIST>
<SCENARIO_STEP Antenna_Area_Definition=" "
Number_Of_Error_Retry="0"
Number_Of_Retry="0" Step_Number=" "/>
</SCENARIO_STEP_LIST>
<FINISH_STEP_LIST/>
</SCENARIO>
<SCENARIO Name="SC3" Services="SEARCH" Used="true">
<SCENARIO_STEP_LIST>
<SCENARIO_STEP
Antenna_Area_Definition="DIAGNOSIS_RIGHT_DOOR_AREA"
Number_Of_Error_Retry="2"
Number_Of_Retry="2" Step_Number="FS_LEARN_SK"/>
<SCENARIO_STEP
Antenna_Area_Definition="DIAGNOSIS_BLUMPER_AREA"
Number_Of_Error_Retry="1"
Number_Of_Retry="1" Step_Number="FS_DISCHARGE_MODE"/>
</SCENARIO_STEP_LIST>
<FINISH_STEP_LIST/>
</SCENARIO>
<SCENARIO Name="SC2" Services="" Used="false">
<SCENARIO_STEP_LIST>
<SCENARIO_STEP Antenna_Area_Definition=" "
Number_Of_Error_Retry="0"
Number_Of_Retry="0" Step_Number=" "/>
</SCENARIO_STEP_LIST>
<FINISH_STEP_LIST/>
</SCENARIO>
<SCENARIO Name="SC1" Services="" Used="false">
<SCENARIO_STEP_LIST>
<SCENARIO_STEP Antenna_Area_Definition=" "
Number_Of_Error_Retry="0"
Number_Of_Retry="0" Step_Number=" "/>
</SCENARIO_STEP_LIST>
<FINISH_STEP_LIST/>
</SCENARIO>
</SCENARIOS>
</BODY_TYPE>
</BODY_TYPES>

it will be generated this table:

PRIVATE_DATA const T_UBYTE cas_Scenarios_BodyType_Table [GET_MAX_NUMBER_OF_BODY_TYPES ]
[ GET_MAX_NUMBER_OF_SCENARIOS] =
{
{
SCENARIO_NUMBER_ROM_BT3_SC4,
SCENARIO_NOT_USED,
SCENARIO_NOT_USED,
SCENARIO_NUMBER_ROM_BT3_SC1
}
,
{
SCENARIO_NOT_USED,
SCENARIO_NUMBER_ROM_BT2_SC3,
SCENARIO_NOT_USED,
SCENARIO_NOT_USED
}
,
{
SCENARIO_NOT_USED,
SCENARIO_NUMBER_ROM_BT1_SC3,
SCENARIO_NOT_USED,
SCENARIO_NOT_USED
}

};


now what I want to do is to replace in the table SCENARIO_NUMBER_ROM_BT1_SC3 with SCENARIO_NUMBER_ROM_BT3_SC4 because they are identical. I need to do this for all the identical SCENARIOS.A problem witch occurs here is that we do not now how many SCENARIO_STEP there are in an SCENARIO node and to find identical SCENARIOS evrey SCENARIO_STEP from one SCENARIO must be identical(have the same attributes) with the SCENARIO_STEP from the other SCENARIO. Do you have an ideea how to do this?


thanks
Andrei

Postnext
Alberto MassariSubject: xml problem
Author: Alberto Massari
Date: 09 Aug 2007 12:12 PM
Hi Andrei,
in order to help you, you should also tell us which version of Stylus Studio you are using, and which language (XSLT/XQuery/etc..) you are using to process this XML.

Thanks,
Alberto

Postnext
andrei dadsaSubject: xml problem
Author: andrei dadsa
Date: 09 Aug 2007 12:48 PM
hi Alberto,

i'm using Stylus Studio 4.5 and the language is xslt

thanks for you help

Posttop
Alberto MassariSubject: xml problem
Author: Alberto Massari
Date: 09 Aug 2007 03:07 PM
Hi Andrei,
unfortunately the only solution I could think of involves xsl:key using a user-defined function to built a unique key from the child nodes, but that is possible only using XSLT 2.0, that Stylus 4.5 doesn't support.
If you want to try it with the current version of Stylus (or just using Saxon 8 standalone), here it is:

<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:local="myNS">

<xsl:function name="local:build-key" as="xs:string">
<xsl:param name="scen"/>
<xsl:variable name="subitems">
<xsl:for-each select="$scen//SCENARIO_STEP">
<xsl:value-of select="concat(@Antenna_Area_Definition, '#', @Number_Of_Error_Retry, '#', @Number_Of_Retry, '#', @Step_Number, '|')"/>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="concat($scen/@Services, '#', $scen/@Used, '_', $subitems)"/>
</xsl:function>

<xsl:key name="scenario" match="SCENARIO" use="local:build-key(.)"/>

<xsl:template match="/">
PRIVATE_DATA const T_UBYTE cas_Scenarios_BodyType_Table [GET_MAX_NUMBER_OF_BODY_TYPES ]
[ GET_MAX_NUMBER_OF_SCENARIOS] =
{
<xsl:apply-templates select="//BODY_TYPE"/>
}
</xsl:template>


<xsl:template match="BODY_TYPE">
{
<xsl:for-each select="SCENARIOS/SCENARIO">
<xsl:variable name="first" select="key('scenario', local:build-key(.))[1]"/>
<xsl:choose>
<xsl:when test="@Used='true'">SCENARIO_NUMBER_ROM_<xsl:value-of select="$first/../../@Name"/>_<xsl:value-of select="$first/@Name"/></xsl:when>
<xsl:otherwise> SCENARIO_NOT_USED</xsl:otherwise>
</xsl:choose>,
</xsl:for-each>
}
</xsl:template>
</xsl:stylesheet>

Hope this helps,
Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.