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 16th, 2009, 06:53 AM
Registered User
 
Join Date: Jan 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display xml comment using xslt

Hi !

I have an xml that looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<Profile name="Default">
<Constants>
<!-- Reference table -->
<add key="APPLICATION" value="1"/>
<!-- Internet dealer -->
<add key="INTERNET" value="2"/>
</Constants>
<Messages>
<add key="Validation" value="Invalid"/>
</Messages>
</Profile>

Now using xslt, it should be able to display the format below. Basically, all the add key in the xml should be in the first column, followed by the value and the comment of the node. Currently, the comment node is not implemented, and I am having a difficulty in adding the comment in the third column since not all xml node have comments. Can any of you provide me a code snippet or syntax that would parse the comment of the xml node and display it in the column of a table?

APPLICATION
1
Reference table

INTERNET
2
Internet dealer
 
Old January 16th, 2009, 07:32 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You want something like this:

<xsl:template match="add">
<xsl:value-of select="@key"/>
<xsl:value-of select="@value"/>
<xsl:value-of select="preceding-sibling::node()[not(self::text()[.=''])][1][self::comment()]"/>

That's basically saying take all the preceding sibling nodes excluding whitespace text nodes; of those take the first (the most recent); then output its value if it is a comment node.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding xml-html transformation of an xml string using xslt and javascript suprakash444 XSLT 1 January 12th, 2009 01:23 AM
XML spreadsheet "comment" element in Excel. Benzion XSLT 3 December 3rd, 2008 12:29 PM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM
XSLT for complicated xml to xml transf. required doug@sirvisetti XSLT 3 June 17th, 2005 04:26 PM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM





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