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 June 26th, 2014, 11:42 PM
Registered User
 
Join Date: Jun 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help Needed to write the correct XSLT

Xml structure like below:

<NonSession>
<Items>
<Item>
<Code>A</Code>
<Description>Desc<Description>
</Item>
<Item>
<Code>B</Code>
<Description>Desc<Description>
</Item>
<Item>
<Code>C</Code>
<Description>Test<Description>
</Item>
<Item>
<Code>A</Code>
<Description>Desc<Description>
</Item>
<Items>
</NonSession>

XSlt like below:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<Errors>
<xsl:apply-templates select="NonSession//Items"/>
</Errors>

<xsl:template match="NonSession//Items">
<xsl:if test="((Item//Code = 'A' or //Item//Code = 'B') and not(Item//Description = 'Desc'))" >
<Error>
<xsl:for-each select="Item">
<XPath>
<xsl:text>/</xsl:text>
<xsl:for-each select="ancestor-or-self::*">
<xsl:value-of select="name()"/>
<xsl:text>/</xsl:text>
</xsl:for-each>
<xsl:text>Desc</xsl:text>
</XPath>
</xsl:for-each>
</Error>
</xsl:if>
</xsl:template>


The final ouput should be something like :
<Errors>
<Error>
All the xpaths of the nodes where ((Code = A or B) and Description != Desc)
<Error>
</Errors>

The if condition in the template is not giving me the exact nodes. Any help would be much appreciated.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i write xslt for the given xml? abcnu XSLT 3 May 28th, 2013 05:04 PM
XSLT Help Needed JZen XSLT 9 February 22nd, 2007 04:27 AM
Correct my xslt for data substitution asap XSLT 0 July 29th, 2006 03:42 PM
help needed for xslt rameshnarayan XSLT 2 September 19th, 2005 03:58 AM
Help Needed to write vba for Pivot Table in Excel sunny76 Excel VBA 1 June 28th, 2005 01:44 AM





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