RE: [xsl] Changing the Attibute Value

Subject: RE: [xsl] Changing the Attibute Value
From: "Buddhi D. Mahindarathne" <buddhi@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 22 Jul 2008 10:13:11 +0530
Dear All,

With all you guys help I managed to make a working XSL sample for my
need, I would say now it is 90% workable. Please give me an answer for
my below 2 questions too...

1. In this XSL we are specifically searching for "ChamferedRectangle1"
in two places, but the last number "1" will change in XML files. So I
need a way of searching only for "ChamferedRectangle" without "1"

2. After first "template match" we are inside the node set, so can't we
do everything with in that, rather than having multiple matches..???

Here is my XSL (please refer far below for my two XML)

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>

   <xsl:template match="@* | node()">
       <xsl:copy>
         <xsl:apply-templates select="@* | node()"/>
       </xsl:copy>
   </xsl:template>

  <xsl:template match="VisualObject[@xsi:type='CChamferEx']">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:attribute name="xsi:type">CFilletEx</xsl:attribute>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="Name[. = 'ChamferedRectangle1']">
   		<xsl:copy>
			<xsl:copy-of select="@*"/>
			<xsl:value-of select="concat(substring-before(.,
'ChamferedRectangle'),'Fillet',substring-after(.,'ChamferedRectangle'))"
/>
        </xsl:copy>
  </xsl:template>

	<xsl:template match="Address[. = 'Laser
Job.Layer.ChamferedRectangle1']">
		<xsl:copy>
			<xsl:copy-of select="@*"/>
			<xsl:value-of select="concat(substring-before(.,
'ChamferedRectangle'),'Fillet',substring-after(.,'ChamferedRectangle'))"
/>
        </xsl:copy>
	</xsl:template>
</xsl:stylesheet>

- Regards
  ____            _     _ _     _
 | __ ) _   _  __| | __| | |__ (_)
 |  _ \| | | |/ _` |/ _` | '_ \| |
 | |_) | |_| | (_| | (_| | | | | |
 |____/ \__,_|\__,_|\__,_|_| |_|_|


-----Original Message-----
From: Buddhi D. Mahindarathne [mailto:buddhi@xxxxxxxxxxxxxxxxxxx]
Sent: Monday, July 21, 2008 12:45 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Changing the Attibute Value


Dear All,
I want to transform following using XSLT 1.0

<VisualObject xsi:type="CChamferEx">
	<maxQSwitch>133</maxQSwitch>
       <Address>Laser Job.Layer.ChamferedRectangle1</Address>
       <Name>ChamferedRectangle1</Name>
       <IsMark>true</IsMark>
       <Visible>true</Visible>
</VisualObject>

And get the output like this:

<VisualObject xsi:type="CFilletEx">
	<maxQSwitch>133</maxQSwitch>
       <Address>Laser Job.Layer.Fillet1</Address>
       <Name>Fillet1</Name>
       <IsMark>true</IsMark>
       <Visible>true</Visible>
</VisualObject>

Here are the things associated with this,

1. Attribute Change
2. Change last part on DOT separated value (I need to keep the last
value with the "Fillet" like [Fillet1] - in the sample number "one")
3. Change the Chamfer to Fillet, but need to keep the last number like
above case.

Please help me on this.

- Regards
  ____            _     _ _     _
 | __ ) _   _  __| | __| | |__ (_)
 |  _ \| | | |/ _` |/ _` | '_ \| |
 | |_) | |_| | (_| | (_| | | | | |
 |____/ \__,_|\__,_|\__,_|_| |_|_|

Current Thread