Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT question

Status
Not open for further replies.

satellite03

IS-IT--Management
Dec 26, 2003
248
IN
XML
====

Code:
<?xml version="1.0" encoding="UTF-8"?>
<discussionForumHome>
<messageBoard id="1" name="Java Programming"/>
<messageBoard id="2" name="XML Programming"/>
<messageBoard id="3" name="XSLT Questions"/>
</discussionForumHome>






XSLT
====


Code:
<xsl:template match="messageBoard">
<li>
<a href="viewForum?id={@id}"> // HTML and @id has been mixed!
<xsl:value-of select="@name"/>
</a>
</li>
</xsl:template>



<xsl:value-of select="@name"/> ---> this is valid because all are XSL compliant

but
<a href="viewForum?id={@id}">

@id is a XSL/Xpath compliant . how can we use it in the anchor tag ? anchor is a html tag. how can i mix both ? is not it wrong ? if it is not wrong ,then whats the rule ?
 
????????

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
It works, and is proper, because the html acts as a template for the output of the XSL translator. The HTML is output by the translator (and the XSL stuff is not) before the browser ever sees it. What is output from the translator to the browser LOOKS like standard html, with no XSL in it. For the example above, what your browser would actually see is something like:
Code:
<li>
<a href="viewForum?id=[red]123[/red]">
[red]ForumX[/red]
</a>
</li>
Where the values in red would have been inserted by the XSL translator.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
you are right. but my question was different.
i am explaing again.

look at this
Code:
<a href="viewForum?id={@id}"> 
<xsl:value-of select="@name"/>


Now see there are @id with curly brace and @name without curly brace . although both of them are attributes of the XML <messageBoard element but they are using different syntax.

[blue]Question :[/blue] So, question is why there are different syntax although they are both the attributes of the same element <messageBoard ?

[blue]Question:[/blue]
You see, in the above <a href is a html tag but @id is not a html thing rather its a XPATH thing. things are mixed here,

i.e
<a href="viewForum?id={@id}"> ==> Html tag anchor + XML attribute in a XPATH syntax (@id)

so, things are mixed here. Neither its a pure html nor a pure XSL statement.

How we can mix this way ? that was my question. If the mixing of these two are legal , then what are the rules ?
 
You can only use XSL Shorthand curly braces (ie {@myVal} ) in attributes.
 
Neither its a pure html nor a pure XSL statement.

Apparently you didn't understand what I tried to explain to you. It's mixed because it is a "template" for the html that will be created by the XSL translator. It has "placeholders" for XSL to insert it's values as it creates the html. I simply cannot put it any simpler than that.

Have you done anything in a server-side programming language, where you freely mix HTML and another language, and the other language controls which HTML gets sent to the browser and what values are inserted into it? Same thing. Most even have a "shorthand" method of inserting simple values into the generated html, much like the curly braces.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top