I would like to use this example for a future conversion using XPATH. Just one of them, if analizyer find e.g 'bcaExercise' that should be convert to element 'exerciseBca' without any values that contains in unitial xml. Just transforming tag to another one. convert to
<?xml version="1.0" encoding="UTF-8"?>
<option>
<abcExercise>
<earliestExerciseTime>
<hourMinuteTime>00:00:00</hourMinuteTime>
</earliestExerciseTime>
<expirationTime>
<hourMinuteTime>11:00:00</hourMinuteTime>
</expirationTime>
</abcExercise>
<bcaExercise>
<earliestExerciseTime>
<hourMinuteTime>00:00:00</hourMinuteTime>
</earliestExerciseTime>
<expirationTime>
<hourMinuteTime>11:00:00</hourMinuteTime>
</expirationTime>
</bcaExercise>
<cbaExercise>
<earliestExerciseTime>
<hourMinuteTime>00:00:00</hourMinuteTime>
</earliestExerciseTime>
<expirationTime>
<hourMinuteTime>11:00:00</hourMinuteTime>
</expirationTime>
</cbaExercise>
</option>
This is my vision of this code. But I have no idea what exectly I should add that can find my initial element by XPATH.
<xsl:template match="option">
<xsl:element name="exerciseAbc">`
</xsl:element>
<xsl:element name="exerciseBca">
</xsl:element>
<xsl:element name="exerciseCba">
</xsl:element>
</xsl:template>
CodePudding user response:
I'm really not sure I understand what you are trying to do.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<!-- identity template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="abcExercise">
<exerciseAbc></exerciseAbc>
</xsl:template>
<xsl:template match="bcaExercise">
<exerciseBca></exerciseBca>
</xsl:template>
<xsl:template match="cbaExercise">
<exerciseCba></exerciseCba>
</xsl:template>
</xsl:stylesheet>
Would give you this output :
<?xml version="1.0"?>
<option>
<exerciseAbc></exerciseAbc>
<exerciseBca></exerciseBca>
<exerciseCba></exerciseCba>
</option>
CodePudding user response:
<xsl:template match="/option" name="changingNameOfElements">
<xsl:for-each select="/option">
<xsl:choose>
<xsl:when test="abcExercise">
<xsl:element name="exerciseAbc"/>
</xsl:when>
<xsl:when test="bcaExercise">
<xsl:element name="exerciseBca"/>
</xsl:when>
<xsl:when test="cbaExercise">
<xsl:element name="exerciseCba"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
This is what I expected was! I find this result and its works! Thanks to everyone who trying to help me.