Solved

XML data binding

Posted on 2002-06-14
25
391 Views
Last Modified: 2013-11-19

I would like to display xml-xsl pages. And would like to choose between native xml-xsl, or data island, or scripted transform.
I've input form elements that must be binded to xml ATTRIBUTES. Can I bind input elements to xml ATTRIBUTES ? Not Nodes ?
How can I do it with the 3 methods ?
1. url points to an xml file (native or asp generated), and in it there's an xsl reference. In the xsl file I have to bind an input text field to a xml attribute.
2. I can load xml and xsl using data islands, and specify datasrc as data island ID, and datafld as attribute name. Is it works ?
3. I can load xml and xsl using javascript, and generate html with transformNode. Using this method, how can I bind a form element to an xml attribute ?

Which is the best method, and why, and how can I specify the binding ?

Binding goals:
I have to send back the filled xml, and I would like to change the xsl (f.e. when the user change the user interface language - asp generated xsl), so previously filled form values must be kept.

   Stewe
0
Comment
Question by:stewe
  • 12
  • 7
  • 5
  • +1
25 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 7077911
actually, stewe, regardless of what method you may choose to employ, what begs the question is why the XSLT file must be dynamic. That is a straight-forward misuse, abuse and violation of the way it is to be used.

The proper way is to have the XML file as dynamic and the XSLT file as static. Unless there is a compelling reason, and even then the XSLT is created via XML and another XSLT.

The XSLT dialect is so powerful that it is to be taken advantage of, not by using ASP code to change the portions of the XSLT which tells me you are using the XSLT to hold DATA.
0
 
LVL 1

Author Comment

by:stewe
ID: 7077925
I have to send back customized xsl. Language, style, based on many things. I don't think xsl dialect is capable for them.
So the question is how can I bind a form's input element to and xml node attribute.

   Stewe
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7077934
I wont attempt to persuade you here about the power of XSLT. But since I fundamentally disagree with your approach, I will step aside and let some other expert take over.

Cheers.
0
 
LVL 1

Author Comment

by:stewe
ID: 7077937
So.

xml file:
<?xml version="1.0" encoding="windows-1252"?>
<?xml-stylesheet type="text/xsl" href="userxsl.asp"?>
<data>
     <User Active="294" UserName="stewe" Name="Stewe" MODSEQ="294" ID="1"/>
</data>

userxsl.xsl file bind section:
<input type="text" size="10" id="UserName" datasrc="#xmlDoc" datafld="/data/User/@UserName"/>

"xmlDoc" data source is just an idea. What should I write for datasrc and datafld attributes ?

   Stewe
0
 
LVL 1

Author Comment

by:stewe
ID: 7077955
The second approach is to generate (design time) more xsl and reference to a right one. I must support more than 10 languages and much more styles.
Example:

lang_eng.asp
<%
var ENG=new LangData();
ENG.WELCOME="Welcome";
ENG.NAME="Name";

%>

run-time:
var l=ENG; (based on cookie, so can be GER,HUN,etc.)

userxsl.asp:

<td><h1><%=l.WELCOME%></h1></td>

If you know better solution, then please tell me.
I generate the lang_esp from an excel file, so translators can simply translate the strings.

  Stewe
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7078017
the way you are using XML is pseudo XML Technologies piggy-backing on older technologies. There is so much that can be said about localising data with XML, but none of it involves dabbling with the XSLT because if you keep on doing that, it is apparent that you have misunderstood the entire concept of XML.

I can understand when limited time and resources bring about certain solutions not entirely satisfactory. But such unsatisfactoriness will manifest itself not tomorrow but when you can no longer extend your solutions short of a complete re-write or dealing with the morass of code. Either way, it is not an envious task.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7078020
dabbling with the XSLT dynamically and dishing it out to the Intranet and/or Internet indicates that you are placing data inside the stylesheets and you have not come up with the correct XML methodology to deal with the task at hand.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7078023
>>
lang_eng.asp
<%
var ENG=new LangData();
ENG.WELCOME="Welcome";
ENG.NAME="Name";

%>

run-time:
var l=ENG; (based on cookie, so can be GER,HUN,etc.)

userxsl.asp:

<td><h1><%=l.WELCOME%></h1></td>
<<

this is precisely what XSLT is designed to replace, and you using it in a reverse fashion.
0
 
LVL 1

Author Comment

by:stewe
ID: 7078029
I undestand it all.
But I need a solution now for binding input elements to xml attributes. Not more. Maybe after a few months, I'll say the same, and I'll rewrite it. But not know, I have to hurry. At least I have to show something to the bosses. And it needs a binding.

  Stewe
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7078032
there is nothing wrong in having the stylesheet stored on the client, and you pass the XML data (dynamic) to the client.

<td>
<h1>
<xsl:value-of select="//Welcome" />
</h1>
</td>

and your XML document is created on the fly in ASP,

<Welcome><%=L.WELCOME=%></Welcome>

This way the presentation rules are cached on the client and so you don't have both XML and XSLT documents dynamic. This is the whole crux of using XML with XSLT. If one doesn't employ XSLT the way it should be used, then one will not reap the benefits of using XML fully.

But I shall stop now and let you enjoy your peace =)))
0
 
LVL 1

Author Comment

by:stewe
ID: 7078046
It's ok.
The problem: using this way, the xml SHOULD KNOW the strings. I think the presentation is not the xml data's business. And when the client is not a browser, then they're unneeded data.

But the binding .... :)
What about it ?
Let's talk about it, please.

   Stewe
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7078094
L.WELCOME is data and not presentation rules.

unsubscribing from question.

Cheers!!
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 7

Expert Comment

by:yoren
ID: 7079803
Stewe,

Can you explain more what you're trying to do (as opposed to the technologies you're using to do it)? Perhaps then I can help.

Yuval
0
 
LVL 1

Author Comment

by:stewe
ID: 7082266
Hi !

I can explain it tomorrow, I have to go now.
So monday morning CET.

   Stewe
0
 
LVL 1

Author Comment

by:stewe
ID: 7083316

  Hi !

So, here's the details:

I've the following xml file userxml.asp (just f.e.):

<?xml version="1.0" encoding="windows-1252" ?>
<?xml-stylesheet type="text/xsl" href="userxsl.asp"?>
<data>
  <User Active="294" UserName="stewe" Name="Stewe" MODSEQ="294" ID="1" />
</data>

Part of the userxsl.asp:
  <input type="text" size="20" id="UserName" datasrc="???" datafld="UserName" />

Question: what should I write into datasrc tag ? I would like to bind that input element to the attribute called 'UserName'.

   Stewe
0
 
LVL 1

Author Comment

by:stewe
ID: 7083324
Another part of the question:

f.e. I've the following xml:
<?xml version="1.0" encoding="windows-1252" ?>
<?xml-stylesheet type="text/xsl" href="userxsl.asp"?>
<data>
 <User Active="1" UserName="stewe" Name="Stewe" MODSEQ="294" ID="1" />
 <Admin Active="1" UserName="admin" Name="Administrator" MODSEQ="22" ID="2" />
</data>

How can I specify that an input element is binded to the first record's "UserName" attribute ? In datasrc or in datafld property ? And with xpath ???

   Stewe
0
 
LVL 7

Expert Comment

by:yoren
ID: 7094879
The datasrc and datafld attributes are not part of HTML. Is that an ASP thing?
0
 
LVL 1

Author Comment

by:stewe
ID: 7095048

It's a client-side stuff, and it works (IE5+ ?)
f.e.

<xml id="mydata" src="userxml.asp">

...

<input size=20 datasrc="#mydata" datafld="UserName">

it works, correctly binded. You can find articles in MSDN library about this feature.
My example is based on the xml data I've posted. BUT. I cannot specify that my control should be binded to record no.2.

   Stewe
0
 
LVL 7

Expert Comment

by:yoren
ID: 7103805
Why are you trying to use the datasrc and datafld features of IE? It makes your code only work with IE, and you can create any HTML you want using XSL.

Here's the XSL you'd need to create an input field with a value defaulting to "stewe" in your example XML file:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">
 <xsl:output method="text"/>
 <xsl:template match="/">
  <![CDATA[<input size="20" type="text"
    value="]]><xsl:value-of select='//data/User[1]/@UserName'/><![CDATA[">]]>
 </xsl:template>
</xsl:stylesheet>
0
 
LVL 1

Author Comment

by:stewe
ID: 7103888
The IE is absolutely needed for me. It's not a prob (intranet application).
I need to bound them, a simply form is not enough.

I have to delete this question, 'cause i've solved the problem without help.

   Stewe
0
 
LVL 7

Expert Comment

by:yoren
ID: 7103942
Glad you figured it out on your own, because everything you posted here makes no sense. You can't bind a form to a dynamically generated XML document.
0
 
LVL 1

Author Comment

by:stewe
ID: 7104044
But I can.
Here's an example:

XML (userxml.asp):
<data>
  <User Name="xxx" UserName="yyy">
</data>

XML DATA ISLAND:
<xml id="user" src="userxml.asp">

XSL:
<input datasrc="#user" datafld="Name">

It works and automatically syncronized every time. So I can change the xsl run-time without loosing the xml data (real-time language change).
0
 
LVL 7

Accepted Solution

by:
yoren earned 100 total points
ID: 7104110
Ah, I misunderstood. I assumed that, since your XML was named .asp, you were dynamically generating it using some logic, in which case updating it would be practically impossible.
0
 
LVL 1

Author Comment

by:stewe
ID: 7104136
Yea, I send it back via HTTP post. Yeah, I know that it's not the prettiest technology. But I've to hurry now, deadline is so close.
0
 

Expert Comment

by:SpideyMod
ID: 8271027
Administrative Action - Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now