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 April 20th, 2007, 10:13 AM
Authorized User
 
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Element validation in a namespace.Please see

How can I ensure that an element exists in a namespace defined for it

I have a namespace http://abc.com/interest and I am giving a prefix 'i:'
In my XSL sheet, I am using the above namespace.

Before I display any element values from an XML file,I would first like to
ensure that a particular element exists in my namespace and only after this
will I display an element value

1)InputDocument.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<ML>
    <Order Acct="MAC" ExDest="ExchDest">
        <Hdr Snt="2007-04-05T13:34:47"/>
        <Instrmt Issr="Barclays" MMY="200903"/>
    </Order>
</ML>
2) Output file format:
Code:
   <i:ID>MAC</i:ID>
   <i:Issr>Barclays</i:Issr>
   <i:Ex>ExchDest</i:Ex>


3) The i:ID,i:Issr element are in the namespace i:.
   So,before I display the elements of InputDocument.xml,
   I will first check whether each element exists in the namespace 'i:'
   and only then display element value of InputDocument.xml

   My XSL:

Code:
  ?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="1.0" 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
   xmlns:fo="http://www.w3.org/1999/XSL/Format" 
   xmlns:i="http://www.abc.com/interests:i" 
   xmlns:fix="http://www.fixprotocol.org/FIXML-4-4">  

   <xsl:template match="ml:ML">
    <xsl:apply-templates select="ml:Order"/>
  </xsl:template>
  <xsl:template match="fix:Order">
 
   Now,here I need to first ensure that element i:ID is existing    in 'i:' and only this is done,I will display the element values:

   <i:ID> -- How do I set this element.? I dont want to hard code this?
   <xsl:value-of select="@Acct"/>
   </i:ID>
  </xsl:template>


  I hope my query is clear.
  Is element validation in the namespace possible?

 
Old April 20th, 2007, 11:08 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm sorry, I really don't understand your question.

Your example appears to use namespace "i:" in the output document but not in the input document. What do you mean when you say "I will first check whether each element exists in the namespace 'i:'"? The output elements don't exist until you create them. Or are you perhaps referring to element definitions in a schema?

Incidentally, your namespace is not called "i:", it is called "http://www.abc.com/interests:i". You are simply using the prefix "i" as a nickname.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem adding element to the previous element dani1 XSLT 5 September 10th, 2008 01:38 AM
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
create XML element with namespace MikeLI Pro Visual Basic 2005 2 June 29th, 2006 08:33 PM
xml validation-namespace is problem asap XML 2 April 26th, 2006 02:56 AM
adding of element and assigning to one element sushovandatta XSLT 2 November 16th, 2004 07:04 PM





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