Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 28th, 2011, 08:02 AM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update value in a different node?

Hi,

Looking at this xml:
Code:
<root>
  <nodeA />
  <nodeB />
</root>
Is it then possible to set the value of nodeB when inside nodeA? For example:
Code:
<xsl:template match="nodeA">
  <!-- Here do something like nodeB.Text = "hi" -->
</<xsl:template>
So that the output of matching nodeA could be (the thing to notice is the content of nodeB):
Code:
<root>
  <nodeA />
  <nodeB>hi</nodeB>
</root>
?

--
Werner

Last edited by ITemplate; January 28th, 2011 at 08:10 AM..
 
Old January 28th, 2011, 08:17 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

No, that's not how XSLT works at all.

I suspect this 'example' you've given here doesn't show anything like your actual requirements, so try to give us a better example showing what your input and output look like and the relationship between them.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old January 28th, 2011, 08:27 AM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for answering,

Well consider this xml:
Code:
<root id="1">
    <node1>
      <node1_1 />
    </node1>
</root>
And this xslt:
Code:
<xsl:stylesheet
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 version="1.0">
<xsl:template match="@*|node()">
  <xsl:copy>
   <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
 </xsl:template>
<xsl:template match="*[not(descendant-or-self::*[text()[normalize-space()] | @*])]">
   <xsl:message>Node <xsl:value-of select="local-name()"/> removed</xsl:message>
</xsl:template>
</xsl:stylesheet>
The result is 1 message:
"Node node1 removed"

However I need also to register that node1_1 was removed. So that I can write the information about what the xslt removed from the input to some log. The input xml could be any valid xml document.

--
Werner

Last edited by ITemplate; January 28th, 2011 at 08:37 AM..
 
Old January 28th, 2011, 08:34 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

See answer in http://social.msdn.microsoft.com/For...a-235b8149b21e
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a node to an existing xml node list. codehelp C# 2008 aka C# 3.0 2 October 12th, 2009 07:41 AM
Displaying data as a Parent Node with Left Node and Right Node Manoj Bisht Visual Basic 2008 Professionals 0 April 2nd, 2009 02:34 AM
Update the node value of XML file Manoj Bisht ASP.NET 3.5 Professionals 6 February 19th, 2009 09:36 AM
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.