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 July 4th, 2007, 06:39 AM
Authorized User
 
Join Date: Jan 2006
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default if an attribute exist

hello

I would like to check if a specific attribute name class exist in the text, and if so print its value, other wise print different value.
meaning, test on the xml if there is class=program exist. if there is, print its value, if there isnt such a class=program exist in the xml print 'nnnnnnn'

this is my xml

<entity eid="B" tid="511" plural-tid="512" grouping-tid="513" plural-grouping-tid="514" length="256">
  <data class="user-defined" type="varchar" dbcolumn="HANDLER_TYPE" mandatory="no" last-summary="all" collection-id="handler-type" />
  </entity>
<entity eid="C" tid="521" plural-tid="522" grouping-tid="523" plural-grouping-tid="524" length="256">
  <data class="user-defined" type="varchar" dbcolumn="CLASS_NAME" mandatory="no" last-summary="all" collection-id="class-name" />
  </entity>
<entity eid="D" tid="531" plural-tid="532" grouping-tid="533" plural-grouping-tid="534" length="256">
  <data class="user-defined" type="varchar" dbcolumn="COMMAND_LINE" mandatory="no" last-summary="all" collection-id="command-line" />
</entity>

thanks

 
Old July 4th, 2007, 06:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry, I don't understand your question. In your sample data, all elements seem to have the same attributes (or attributes with the same names but different values). Perhaps you could explain what output you want from this data.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 4th, 2007, 07:09 AM
Authorized User
 
Join Date: Jan 2006
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry my mystake.
what I meant is to check if there is class name "program".
if there is class="program" print YYY if there is no such class with value "program" pring NNN.

 
Old July 4th, 2007, 07:23 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Assuming you don't care what element the attribute appears on, use

<xsl:when test="//@class='program'">YYY</xsl:when>
<xsl:otherwise>NNN</xsl:otherwise>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 4th, 2007, 07:24 AM
Authorized User
 
Join Date: Jan 2006
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this is an example of input that should pring 'NNNNN' becuase there is no class='program'.
again, I want to know how can I test if there is class="program' in the input file?

<entity eid="U" tid="511" plural-tid="512" grouping-tid="513" plural-grouping-tid="514" length="256"><display mandatory="no" order="6"></display><data class="user_name" type="varchar" dbcolumn="SENDER" mandatory="yes" last-summary="all" collection-id="sender"></data><load allow-drop="no"></load><integration alerts="yes" foresight="yes"></integration><service-time></service-time></entity>

<entity eid="C" tid="521" plural-tid="522" grouping-tid="523" plural-grouping-tid="524" length="256"><display mandatory="no" order="7"></display><data class="client_ip" type="varchar" dbcolumn="SENDER_IP" mandatory="yes" last-summary="all" collection-id="C_IP"></data><load allow-drop="no"></load><integration alerts="yes" foresight="yes"></integration><service-time></service-time></entity>

<entity eid="T" tid="531" plural-tid="532" length="256">
<display mandatory="no" order="9"></display><data class="user-defined" type="varchar" dbcolumn="MSG_TYPE" mandatory="yes" last-summary="all" collection-id="type"></data><load allow-drop="no"></load><integration alerts="yes" foresight="yes"></integration><service-time></service-time></entity>






Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace an attribute with another attribute georgemeng XSLT 8 June 10th, 2008 11:04 AM
If Exist then Update Neal SQL Server 2000 4 July 25th, 2007 07:49 AM
record exist or not keyvanjan Classic ASP Basics 2 May 5th, 2006 11:39 AM
Table Exist? elansolutionsltd Access VBA 5 January 23rd, 2006 03:43 AM
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM





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