stewe
asked on
XML data binding
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
ASKER
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
So the question is how can I bind a form's input element to and xml node attribute.
Stewe
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.
Cheers.
ASKER
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/@UserN ame"/>
"xmlDoc" data source is just an idea. What should I write for datasrc and datafld attributes ?
Stewe
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/@UserN
"xmlDoc" data source is just an idea. What should I write for datasrc and datafld attributes ?
Stewe
ASKER
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
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
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
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.
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.
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.
>>
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.
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
<<
this is precisely what XSLT is designed to replace, and you using it in a reverse fashion.
ASKER
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
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
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 =)))
<td>
<h1>
<xsl:value-of select="//Welcome" />
</h1>
</td>
and your XML document is created on the fly in ASP,
<Welcome><%=L.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 =)))
ASKER
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
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
L.WELCOME is data and not presentation rules.
unsubscribing from question.
Cheers!!
unsubscribing from question.
Cheers!!
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
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
ASKER
Hi !
I can explain it tomorrow, I have to go now.
So monday morning CET.
Stewe
I can explain it tomorrow, I have to go now.
So monday morning CET.
Stewe
ASKER
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
ASKER
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
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
The datasrc and datafld attributes are not part of HTML. Is that an ASP thing?
ASKER
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
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]/@Us erName'/>< ![CDATA["> ]]>
</xsl:template>
</xsl:stylesheet>
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]/@Us
</xsl:template>
</xsl:stylesheet>
ASKER
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
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
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.
ASKER
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).
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).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
Administrative Action - Force Accepted
SpideyMod
Community Support Moderator @Experts Exchange
SpideyMod
Community Support Moderator @Experts Exchange
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.