473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XSLT : Amend element value

Hi,

i need to amend the value stored in the element in XSLT and this needs to be carried out with in a <template> code..

Please can you help me how to do this?

in the below code, in "GetTypeListValue" template call i need to amend the value stored in the input parameter (NodeName) with the value derived with in the template..

Thanks in adv for your help/comments

Cheer
Venu

Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  >
  2.  
  3.     <xsl:template name="GetTypeListValue">
  4.         <xsl:param name="NodeName"/>
  5.         <xsl:copy>
  6.             <xsl:variable name="sInput" select="$NodeName"></xsl:variable>
  7.             <xsl:variable name="sTLValue">
  8.                 <xsl:choose>
  9.                     <xsl:when test="$sInput = '01'"><xsl:value-of  select="Description1"/></xsl:when>
  10.                     <xsl:when test="$sInput = '02'"><xsl:value-of  select="Description2"/></xsl:when>
  11.                 </xsl:choose>
  12.             </xsl:variable> 
  13.             <xsl:value-of select="$sTLValue"/>
  14.              <!-- i need to update the value stored $NodeName with the derived value $sTLValue here.. -->  
  15.  
  16.         </xsl:copy>
  17.     </xsl:template>
  18.  
  19.  
  20.     <xsl:template name="Get_CustomerDetail">
  21.         <xsl:call-template name="GetTypeListValue">
  22.             <xsl:with-param name="NodeName" select="/CompositionRequest/Request/Type"/>
  23.         </xsl:call-template>
  24.     </xsl:template>
  25.  
  26.     <!-- copy the data -->
  27.     <xsl:template match="*">
  28.         <xsl:copy>
  29.             <xsl:copy-of select="@*"/>
  30.             <xsl:apply-templates/>
  31.         </xsl:copy>
  32.     </xsl:template>
  33.  
  34. </xsl:stylesheet>
  35.  
Jun 18 '08 #1
3 2391
jkmyoung
2,057 Expert 2GB
What you're doing seems like a really roundabout way of accomplishing what you want. Could you post some source xml, and expected xml, highlighting the change? There's probably a better way to do this.

Where is your template even called?
Jun 18 '08 #2
Hi,

thanks for looking at this.

i need to reuse the template to get the description for below node, hence i thought of calling the templae by passing the element-path as input parameter.
Please let me know if anything wrong here.

1) /CompositionRequest/Request/Type
2) /CompositionRequest/Request/Data/Type[@id='1']
3) /CompositionRequest/Request/Data/Type[@id='2']


Thanks for your help

Cheers
Venu

This is the sample XML as the original XML is big and i can't re-build the expected XML in the XSLT - hence i'm copying it and trying to amend selected element value.

Source XML (elements that needs to be changed are in bold)
Expand|Select|Wrap|Line Numbers
  1. <CompositionRequest>
  2.     <Request>
  3.         <Type>01</Type>
  4.         <Data>
  5.             <Type id='1'>02</Type>
  6.             <Type id='2'>03</Type>
  7.             <custname>Jones</custname>
  8.         </Data>
  9.         <Header>
  10.             <template_name>V8_1</template_name>
  11.             <version>000125</version>
  12.             <job_date>2008/06/10</job_date>
  13.             <job_id>12455252</job_id>
  14.         </Header>
  15.     </Request>
  16. </CompositionRequest>
  17.  
Expected XML (elements that needs to be changed are in bold)
Expand|Select|Wrap|Line Numbers
  1. <CompositionRequest>
  2.     <Request>
  3.         <Type>Description1</Type>
  4.         <Data>
  5.             <Type id='1'>Description2</Type>
  6.             <Type id='2'>Description3</Type>
  7.             <custname>Jones</custname>
  8.         </Data>
  9.         <Header>
  10.             <template_name>V8_1</template_name>
  11.             <version>000125</version>
  12.             <job_date>2008/06/10</job_date>
  13.             <job_id>12455252</job_id>
  14.         </Header>
  15.     </Request>
  16. </CompositionRequest>
  17.  
Jun 19 '08 #3
jkmyoung
2,057 Expert 2GB
Are you changing all Type nodes in general, or only the specified ones?
If it's all the type nodes, it would be simpler to have a 'Type' template.

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="Type">
  2.   <xsl:copy>
  3.      <xsl:choose>
  4.         <xsl:when test=". = '01'"><xsl:value-of  select="Description1"/></xsl:when>
  5.         <xsl:when test=". = '02'"><xsl:value-of  select="Description2"/></xsl:when>
  6.         <xsl:otherwise><xsl:value-of select="Description"/></xsl:otherwise>
  7.      </xsl:choose>
  8.   </xsl:copy>
  9. </xsl:template>
  10.  
Further, are you looking for nodes Description1, Description2, etc. or are you using the text "Description1"? If just the text, then add single quotes around it ('text') or get rid of the <xsl:value-of> part, so it is treated as text. eg
<xsl:otherwise>Description</xsl:otherwise>

--------

If it's only the xpath specified ones, it becomes a lot harder. You'd have to use an evaluate extension function to do this easily.
Jun 19 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
6
by: Bloody Viking | last post by:
Namaste, Y'all. Given an element A containing elements B,C,D,E,F, I need to create a variable that gets the value of element C, conditionally followed by the value of element D, only if the...
2
by: Sharkie | last post by:
I'm relatively new to XSLT, having strong background in bunch of other programming languages (Perl, Java, etc.). I'm writing an XSLT stylesheet, converting XML into HTML. Everything works just...
0
by: shapper | last post by:
Hello, I am transforming a XML file into another XML file using a XSLT. Everything is working fine! I have only one problem: I want one of the values in my XSLT file to be taken from a Key...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
2
by: bharadwajrv | last post by:
Hi: i have a XML file (at least 1000+ elements) and i need to amend the value of one element and need to retain the original structure of XML intact. Source XML:- <root> <node1></node1>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.