Wiki Home

Using XSLT

Namespace: WIN_COM_API
Using XSLT - a WNL by Mike Helland.

XSLT - eXtensible Stylesheet Language: is used to transform XML documents to nearly any type of document needed, even XML itself.

It is a conversion definition language.
Editor's note: All "<" and ">" signs in the XML have been replaced with "{" and "}" to fool the Wiki parser.

[21:03] {MikeHelland} Hi ya'll

[21:03] {MikeHelland} Who here is awake first off?

[21:03] {CindyWinegarden} Me

[21:03] {CarlKarsten} 1/2

[21:03] {BarbaraPeisch} Only half - I spent half the day in Phoenix.

[21:04] {MikeHelland} Jet lag?

[21:04] {BarbaraPeisch} Naw, it's in the same time zone. I just didn't sleep well. (Up too late!)

[21:04] {BarbaraPeisch} Well, it's not realy the same time zone--they just done have daylight savings time over there.

[21:04] {BarbaraPeisch} done = don't

[21:05] {MikeHelland} AHh, I see

[21:05] {MikeHelland} Ok ,well, to start off, my name's Mike

[21:05] {MikeHelland} And ask me anything you want in the middle of this

[21:05] {MikeHelland} Now, if you want to play with any of my samples, you'll need the MSXML Parser, version 3.0

[21:05] {MikeHelland} You can get it here:

[21:05] {MikeHelland}

[21:06] {MikeHelland} The Parser has a COM interface that you can use to parse XML documents

[21:06] {MikeHelland} You can also use this version of the parser to do XSLT

[21:06] {MikeHelland} Now, the obvious, what is XSLT?

[21:06] {MikeHelland} I'm going to assume you have a semi understanding of XML, if not, just shout it out

[21:07] {MikeHelland} XSLT is a language that you can use to transform your XML documents into any type of text based output you want

[21:07] {MikeHelland} Typically, most people use these transformations to create HTML out of XML data, but it can go to RTF, text file, WML, or anything you really want

[21:08] {MikeHelland} XSLT stands for eXtensible Stylesheet Langauge Transformations

[21:08] {MikeHelland} Thought thats not important to understing how to use it

[21:08] {MikeHelland} XSLT is apart of XSL, though thats not all to important either

[21:09] {MikeHelland} What is important, is that stylesheets, XSLT documents, are actually stored as XML documents themselves

[21:09] {MikeHelland} That means that when you are creating XSLT, they follow the same rules XML does

[21:10] {MikeHelland} Well formed (meaning you can't leave a tag open without closeing it) and it always has to use quotes in attributes (instead of bgcolor=red it should be bgcolor="red")

[21:10] {MikeHelland} And also, using & or { or simialar needs to be encoded to valid HTML

[21:11] {MikeHelland} they end up being & and <

[21:11] {MikeHelland} Any questions so far?

[21:11] {MikeHelland} Alrighty

[21:11] {MikeHelland} The examples I'm going to show you today will be transformed on my server

[21:12] {MikeHelland} The alternative to that is using your browser to do the transformation

[21:12] {MikeHelland} Unfortunaely, not all browser support client side XSLT

[21:12] {MikeHelland} As a matter of fact, IE5 is the only one I know off hand that does

[21:13] {MikeHelland} So, lets start off by looking at an XML document

[21:13] {MikeHelland} Take a look at:

[21:13] {MikeHelland} If you have IE5, you should see a fancy layout of the XML document

[21:13] {MikeHelland} If you don't, yo ushould be able to click "View Source" to see the XML

[21:14] {MikeHelland} Everyone see that?

[21:14] {CarlKarsten} um, yea...

[21:14] {BarbaraPeisch} Yup

[21:14] {MikeHelland} Lets say this XML document was created by some type of program that read it out of an email client

[21:15] {MikeHelland} If you wanted to use this over the web, its not very handy

[21:15] {MikeHelland} Cause you're looking at raw XML

[21:15] {MikeHelland} One thing you could do, is instead of creating an XML document, actually, create a pretty HTML document out of your data instead

[21:16] {MikeHelland} UNfortunately, that means that your data and your presentation will be tightly - coupled

[21:16] {MikeHelland} We want a solution that leaves them seperated

[21:16] {MikeHelland} So if I ever wanted to view my message in another form, like through WAP, or a textfile, all I will need to do is select a new presentation format

[21:16] {MikeHelland} They way we can do this is with XSLT

[21:17] {MikeHelland} Using a stylesheet, I'll show you how to take your XML message, merge it with your XSL stylesheet and show it in a browser

[21:17] {MikeHelland} I'm going to use one ASP page in this process

[21:18] {MikeHelland} The ASP simply accepts the name of the XML document, XSL document, merges them together and throws them back at teh browser

[21:18] {MikeHelland} The url for that is code is

[21:19] {MikeHelland} I use a VB Script to create to instances of the XML parser, one for the XML and one for the XSL (since XSL is an XML doc) and then call TransFromNode() to do the transformation

[21:19] {MikeHelland} This code can be easily ported to VFP

[21:20] {MikeHelland} Everyone still following?

[21:20] {chrisj} Got it...

[21:20] {BarbaraPeisch} Yes

[21:20] {MikeHelland} So, right to the chase, this is what our message looks like after transforming it with the stylesheet I will show you in a little bit

[21:20] {MikeHelland}

[21:20] {MikeHelland} Does everyone see a nicely formated message?

[21:21] {CarlKarsten} purdy

[21:21] {MarkusVoellmy} yoh

[21:21] {chrisj} beautiful...

[21:21] {Vinicio} cool

[21:21] {BarbaraPeisch} Cool!

[21:21] {MikeHelland} Ok, here is teh XSL for that, we'll go through it line by line

[21:21] {MikeHelland}

[21:21] {MikeHelland} Once again, you should be able to View Source if you can't see it directly

[21:22] {MikeHelland} The first line is stanard XML header

[21:22] {MikeHelland} Just learn it :-)

[21:22] {MikeHelland} The second line does acouple things

[21:22] {MikeHelland} It defines an XSL namespace to use in our document

[21:23] {MikeHelland} That means, whenever it encouters a node in our XML prefifed with "xsl:" it will know its an XSL node

[21:23] {MikeHelland} OTherwise, the tags will just become apart of the output tree

[21:23] {MikeHelland} And I'll explain that as I go

[21:23] {MikeHelland} Here's the next line:

[21:23] {MikeHelland} {xsl:template match="/"}

[21:24] {MikeHelland} This is telling you that you have an XSL template you will apply to everything that the "match" selects

[21:24] {MikeHelland} Now this is what makes XSLT/XML hard

[21:24] {MikeHelland} It uses somethign called XPath to gather matches

[21:24] {MikeHelland} An analogy

[21:24] {MikeHelland} Databases see SQL to select parts of a table

[21:25] {MikeHelland} XSLT uses XPath to select the part of the XML document you want to use

[21:25] {MikeHelland} the XPath "exprsession" "/" means you will start at the very root of the document

[21:25] {MikeHelland} This should hopeuflly start tomake more sense after we see some more examples

[21:26] {MikeHelland} Next. we see "HTML" and "BODY" tags

[21:26] {MikeHelland} Yay! Somethign thats hopefully familiar

[21:26] {MikeHelland} These tags are not "xsl:" tags, so that means that they will be sent as text to the output tree

[21:26] {MikeHelland} As we keep going its normal HTML as usual

[21:27] {MikeHelland} Then we hit:

[21:27] {MikeHelland} {font color="white"}{b}{xsl:value-of select="message/subject" /}{/b}{/font}

[21:27] {MikeHelland} We see antoher XSL: tag

[21:27] {CarlKarsten} im lost - what font tag??

[21:27] {MikeHelland} The Value-Of tag uses the "Select" attribute to get some data, and then it adds that data to the output tree

[21:28] {MikeHelland} Carl, is that a serious question?

[21:28] {CarlKarsten} y

[21:28] {MikeHelland} No offense

[21:28] {MikeHelland} Ok

[21:28] {MikeHelland} FONT is simply more HTML

[21:28] {MikeHelland} Just like the P and B and HTML tags we've already seen

[21:28] {CarlKarsten} righ - but I don;'t see a font tag

[21:28] {MikeHelland} Oh, its a couple lines down

[21:29] {MikeHelland} I went from HTML and BODY, and then I skipped some other normal HTML tags and ended up at the Font tag

[21:29] {MikeHelland} See what I mean?

[21:29] {CarlKarsten} Ioh!

[21:29] {CarlKarsten} i see it...

[21:29] {MikeHelland} Ok

[21:29] {MikeHelland} Now, in our XSL, we have:

[21:29] {MikeHelland} {font color="white"}{b}{xsl:value-of select="message/subject" /}{/b}{/font}

[21:30] {MikeHelland} If you look at the formatted message again, and look in the source, you'll see:

[21:30] {MikeHelland} {font color="white"}{b}From: {a href="mailto:[email protected]"}Carl Karsten{/a}{/b}{/font}

[21:30] {MikeHelland} Whopps,not that line:

[21:30] {MikeHelland} {font color="white"}{b}DevCon Orlando{/b}{/font}

[21:30] {MikeHelland} What happened hereis this

[21:31] {MikeHelland} This line sets the "context"

[21:31] {MikeHelland} {xsl:template match="/"}

[21:31] {MikeHelland} That means that any XPath after that MATCH will be relative to teh MATCH

[21:31] {MikeHelland} Since Match is the total top of teh tree, in order to get "DevCon Orlando" from myXML document

[21:32] {MikeHelland} (Which was this again

[21:32] {MikeHelland} I need to go INTO the message node and tehn INTO the subject node

[21:32] {MikeHelland} Thats what "message/subject" in teh Value-Of tagmeans

[21:32] {MikeHelland} Is anyone confused, I know, its pretty tricky

[21:33] {BarbaraPeisch} I'm pretty confused

[21:33] {DenisChasse} It's a bit fast.

[21:33] {MikeHelland} I figured I wouldn't do a good job teh first time around, let me try again :-)

[21:33] {MikeHelland} Our XML document looks like this:

[21:34] {MikeHelland} {?xml version="1.0"}{message}{subject}DevCon Orlando{/subject}...

[21:34] {DenisChasse} You're doing a good job it's just that it's a lot of switching to the chat and then xml and then output window. I get confused a bit

[21:34] {MikeHelland} Ok, now, to reference a value in XML, we use XPath, which is hard to say the least

[21:34] {MikeHelland} I understand Denis :-)

[21:35] {MikeHelland} I'll tryand put it all in teh chat for the beginning here

[21:35] {MikeHelland} So the way to get the subject in XPath looks like this "message/subject"

[21:35] {MikeHelland} The part that is tricky are teh contexts

[21:36] {MikeHelland} And that should make more sense latter on, after a few more examples

[21:36] {BarbaraPeisch} What's confusing to me is that you have "message/" in front of all your {xsl:... tags. You show a {message} tag in the xml, but where's the {/message}?

[21:36] {MikeHelland} But for now, back to the Value-Of tag

[21:36] {MikeHelland} The message is at the very end

[21:36] {MikeHelland} The /message is at the very end

[21:36] {MikeHelland}

[21:36] {BarbaraPeisch} You mean at the end of the XML doc, right?

[21:37] {MikeHelland} Yep

[21:37] {BarbaraPeisch} So is the "message" part of the template saying it's in the {message} part of the XML?

[21:37] {MikeHelland} Yes!

[21:37] {BarbaraPeisch} OK, I think I'm starting to get it!

[21:37] {MikeHelland} And when I say this in the template:

[21:37] {MikeHelland} {xsl:value-of select="message/subject" /}

[21:38] {MikeHelland} It really means to substitue the whole tag for the value it selects

[21:38] {MikeHelland} Which is teh Subject node int eh Message Node

[21:38] {MikeHelland} Thats why in the XSL you see:

[21:38] {MikeHelland} {font color="white"}{b}{xsl:value-of select="message/subject" /}{/b}{/font}

[21:38] {MikeHelland} And after the XML is transformed you see:

[21:39] {MikeHelland} {font color="white"}{b}DevCon Orlando{/b}{/font}

[21:39] {BarbaraPeisch} OK, now it really makes sense. It's kind of hard when you can't see the XSL and the XML at the same time.

[21:39] {MikeHelland} In the source of the HTML (the pretty message)

[21:39] {MikeHelland} Barbara.. agreed

[21:39] {MikeHelland} But thats the point, the presentation here is seperated from the data

[21:39] {MikeHelland} Kindof frustrating,eh?

[21:40] {BarbaraPeisch} It's not frustrating to separate them programmatically--it's when you're learning that it's hard.

[21:40] {MikeHelland} Yep

[21:40] {MikeHelland} Ok, if anyone else is confused, thats ok, but I'll move along until I get a question

[21:41] {MikeHelland} Later on down the road, we start to see a real mess, for exmaple, a fewlines down, I have:

[21:41] {MikeHelland} {font color="white"}{b}From: {a}{xsl:attribute name="href"}mailto:{xsl:value-of select="message/from/email" /}{/xsl:attribute}{xsl:value-of select="message/from/displayname" /}{/a}{/b}{/font}

[21:41] {MikeHelland} Ack!

[21:41] {MikeHelland} What I'm trying to do here, is get the value of an XML node into the hyper link of the name

[21:41] {MikeHelland} Lets look atthe message again:

[21:41] {MikeHelland}

[21:42] {MikeHelland} You see how "Carl Karsten" is a hyper link to ""?

[21:42] {MikeHelland} You can tell by putting your mouse over the link in IE and teh url will be shown on the bottom

[21:42] {MikeHelland} Well, the syntax for that is:

[21:42] {MikeHelland} {a href="mailto:[email protected]"}Carl Karsten{/a}

[21:43] {MikeHelland} Unfortunatly, we can't simply use "value-of" to put Carl's email in teh link

[21:43] {BarbaraPeisch} So, it seems that the parser will always assume that the value of the attribute is always after the last / in the xsl: line.

[21:43] {BarbaraPeisch} and the rest are the tags to get there

[21:43] {MikeHelland} {a href="mailto:"{xsl:value-of select="from/email" /}}Carl...

[21:44] {MikeHelland} We can't do that because thats improper XML

[21:44] {MikeHelland} Barbara, true for teh examples we've seen so far

[21:44] {MikeHelland} XPath is WAY complicated (but accordingly powerful :-)

[21:44] {CarlKarsten} um

[21:44] {MikeHelland} Does that make sense why having a tag in a tag is not well formed HTML/XML?

[21:44] {MikeHelland} Its just teh rules

[21:44] {MikeHelland} Yes Carl

[21:45] {CarlKarsten} do things being outpted directly need to be valid tags?...

[21:45] {DenisChasse} Is XPath included when you download MSXML?

[21:45] {CarlKarsten} like the {html} at the beginning

[21:45] {MikeHelland} Outputed? No, you can output anything you want. It can be a comma delimited text file, or another XML file

[21:46] {MikeHelland} But, if you do use {HTML} tags in the output, they need to be in wellformed form too, because they are still tags in teh XML docuement that is the XSL file

[21:46] {MikeHelland} What a mouthfull?

[21:46] {MikeHelland} Denus, use, XPath is built into MSXml

[21:46] {MikeHelland} Denis, yes...

[21:46] {MikeHelland} rather

[21:46] {MikeHelland} So here is how teh tag in a tag is done

[21:46] {MikeHelland} We use the xsl:attribute tag

[21:47] {CarlKarsten} so couldn't the mailto be built a pice at a time

[21:48] {MikeHelland} {a} {xsl:attribute name="href"} mailto: {xsl:value-of select="message/from/email" /} {/xsl:attribute}

[21:48] {MikeHelland} Explain, Carl?

[21:48] {MikeHelland} The HTML tags do need to be in the proper XML form since they are tags

[21:48] {CarlKarsten} in the xsl, could the 'From:' be 'From {a href="mailto: '

[21:49] {MikeHelland} But they don't need to be proper HTML anything, since it doesn't care about what the output does

[21:49] {MikeHelland} Keep going with teh example

[21:49] {CarlKarsten} wait, you said that { need to be >

[21:49] {MikeHelland} If you are using the { in the middle of a sentence

[21:49] {CarlKarsten} From {a href="mailto:

[21:50] {MikeHelland} That will come out in the output as exactly what you tell it: {a href

[21:50] {MikeHelland} You want it to come out as {a href

[21:50] {MikeHelland} Its confusing, because you're not dealing with strings like in VFP

[21:50] {BarbaraPeisch} Carl, I think it's confusing because it's interpretting the XSL as both a regular HTML parser and XSL paser at the same time.

[21:50] {CarlKarsten} yea...

[21:50] {MikeHelland} You're merging two documents together, and there is a third skeleton document in the middle

[21:51] {BarbaraPeisch} So, if it doesn't see {xsl: at the start of the tag, it interprets it as HTML, otherwise, it does the XPath thing.

[21:51] {MikeHelland} Barbara, it coudl care less aobut the HTML Tags, other than the fact that they ARE tags and need to fit in an XML document perfectly'

[21:52] {BarbaraPeisch} OK, now you're confusing me again.

[21:52] {CarlKarsten} ohhh!!! this IS the html

[21:52] {CarlKarsten} no, wait...

[21:52] {MikeHelland} If it doesn't see the "xsl:" the TRANSFORMATION interperates it as output

[21:52] {BarbaraPeisch} Carl, that's what I thought, but Mike's saying otherwise.

[21:52] {BarbaraPeisch} Oh, so I was right, more or less.

[21:52] {CarlKarsten} yea, that's the html (points to source of purdy page)

[21:53] {MikeHelland} Wether or not it has an "xsl:" though, ALL TAGS have to be well formed, since teh whole docuement is an XML

[21:53] {CarlKarsten} I am back to being confused

[21:53] {MikeHelland} Carl, do you have IE5?

[21:53] {CarlKarsten} yea

[21:53] {MikeHelland} View:

[21:53] {CarlKarsten} y

[21:53] {MikeHelland} Notice how even the HTML tags are treated as lines (they have the plus and minus to the left)

[21:54] {CarlKarsten} ok

[21:54] {MikeHelland} Because they are still tags in teh XML docuement

[21:54] {MikeHelland} The XML document you are looking at is an XSL stylesheet

[21:54] {MikeHelland} But its still XML

[21:54] {MikeHelland} So all tags, regardless of namespace (the "xsl:") need to fit teh XML

[21:55] {MikeHelland} The document is used in a TRANSFORMATION, thats when teh distinguishing between xsl and output data (doesn't have to be tags) are used

[21:55] {MikeHelland} Does that make sense?

[21:55] {CarlKarsten} If I was building the html in vfp, i don't need to worry about it, because vfp dosn't read tags. but because XSL does do tags, I need to make sure my tags are in order?

[21:56] {MikeHelland} Yeppers

[21:56] {MikeHelland} So our:

[21:56] {MikeHelland} {a href="mailto:"{xsl:value-of select="from/email" /}}Carl...

[21:56] {MikeHelland} won't work

[21:56] {MikeHelland} Lets get back to that

[21:56] {MikeHelland} The SOlution is this

[21:56] {MikeHelland} {a} {xsl:attribute name="href"} mailto: {xsl:value-of select="message/from/email" /} {/xsl:attribute}

[21:57] {MikeHelland} What is happening is we are starting our A tag and not specifiying an href attribute

[21:57] {BarbaraPeisch} Yeah, that part's confusing, 'cause I don't see where you ever output the href for the HTML tag.

[21:58] {Vinicio} where the Href gets the = to be href= ?

[21:59] {MikeHelland} Instead, we immediately go to teh {xsl:attribute} which tells the TRANSFORMATION to send whatever is in between the {xsl:attribute} and {/xsl:attribute} to an attribute in the last tag in teh out put file

[21:59] {MikeHelland} So {a} {xsl:attribute name="href"}mailto:{/xsl:attribute} gets transformed to:

[21:59] {MikeHelland} {a href="mailto:"}

[22:00] {MikeHelland} Using that formuala, we can add anythign else we want in between the attribute tags

[22:00] {MikeHelland} INcluding a Value-Of:

[22:00] {MikeHelland} {xsl:value-of select="message/from/email" /}

[22:00] {MikeHelland} Now this selects the EMAIL from the FROM from teh MESSAGE using XPath

[22:01] {MikeHelland} Here is teh orginal XML data again:

[22:01] {MikeHelland}

[22:01] {MikeHelland} Vincio, exactly correct

[22:02] {MikeHelland} Any questions on that little mess?

[22:02] {BarbaraPeisch} It takes some digesting, but makes sense.

[22:02] {MikeHelland} If you finish out teh XSL file

[22:02] {MikeHelland}

[22:02] {MikeHelland} There should be no more surprises

[22:03] {CarlKarsten} so the = is added because that is how a name=value pair looks?

[22:03] {MikeHelland} Just adding teh body the same way we added the title, and closing some more tags

[22:03] {MikeHelland} Yes

[22:03] {CarlKarsten} you specify the name and the value, and it puts the = in there?

[22:03] {MikeHelland} You bet

[22:03] {MikeHelland} Kindof wild, eh

[22:03] {MikeHelland} Ok, thats a nice little example

[22:04] {DenisChasse} Tat was really nice

[22:04] {DenisChasse} tat = that

[22:04] {MikeHelland} Maybe the attribute was a little tough, but II'm glad I did it right away

[22:04] {MikeHelland} Now, lets take a look at a few more examples, and call it a night, anyone?

[22:04] {DenisChasse} I did'nt see why I would need XML before tonight's presentation

[22:04] {MikeHelland} :-)

[22:05] {MikeHelland} Lets say I want to show mutliple messages in my emial page?

[22:05] {MikeHelland} Here's the latest and greatest XML:

[22:05] {MikeHelland}

[22:05] {MikeHelland} This has four messages in it

[22:05] {MikeHelland} 2 from Carl, one from Bill Gates, and one from Claudia Schiffer, seriosuly folks, I don't know what she's tlaking about

[22:05] * Mike Helland sweats

[22:06] {CarlKarsten} he he

[22:06] {MikeHelland} Ok, lets look at how that can be formated too

[22:06] {MikeHelland}

[22:06] {MikeHelland} If you'll notice, its very simialr to what we already saw

[22:06] {MikeHelland} Everyone seeing these?

[22:06] {BarbaraPeisch} Why do I only see 2 message?

[22:07] {CarlKarsten} your windows not big enought? ;)

[22:07] {BarbaraPeisch} Nevermind, it was just slow.

[22:07] {CarlKarsten} i see 4

[22:07] {DenisChasse} yep

[22:07] * Mike Helland hugs his server and tells her not to listen to Barabara

[22:07] {MikeHelland} Ok, so, lets look at the XSL file for that bad boy

[22:07] {DenisChasse} hehe

[22:07] {MikeHelland}

[22:08] {MikeHelland} Its easier to view teh source when you follow along with teh XSLs

[22:08] {MikeHelland} So basically, it starts off the exact same way the other one did, but then we see this:

[22:08] {MikeHelland} {xsl:for-each select="root/message"}

[22:08] {MikeHelland} Holy Crap, whats that! A For Loop? IN a style sheet?

[22:09] {MikeHelland} You bet

[22:09] {MikeHelland} You can see it also uses XPath, to create a set of nodes it will loop on

[22:09] {MikeHelland} It finds every "message" node in teh "root" node

[22:09] {MikeHelland} And then does transformations on that

[22:09] {MikeHelland} Here's teh hard part about XPath that always finds away to confuse you

[22:10] {MikeHelland} When you do teh For-Each

[22:10] {MikeHelland} You are changing the "context" of the stylesheet

[22:11] {MikeHelland} That means that since you selected all nodes that meet: "root/subject", from then on, the XPath you use will be relative to "root/subject" because it became teh context

[22:11] {MikeHelland} So instead of:

[22:11] {DenisChasse} With...EndWIth ?

[22:11] {MikeHelland} {xsl:value-of select="message/subject" /}

[22:11] {MikeHelland} in the orginal one, we know only need to do:

[22:11] {MikeHelland} {xsl:value-of select="subject" /}

[22:11] {MikeHelland} Denis, excellent!!!!!

[22:12] {MikeHelland} I never thought of it like that!

[22:12] {CarlKarsten} got it

[22:12] {Vinicio} relative path?

[22:13] {MikeHelland} Other than putting a For-Each around part of the XSL and the simplifed XPath uses, this XSL is exactly the same as the last one

[22:13] {MikeHelland} Yes Vincio

[22:13] {MikeHelland} Any questinos, before the final example?

[22:13] {MikeHelland} ANyone blurt it out if they are confused

[22:14] {MikeHelland} Cool

[22:14] {MikeHelland} Ok, last example.

[22:14] {MikeHelland} In this example, 'm gonna show you how complicated I can get XPath

[22:14] {MikeHelland} I will use it to Filter, Sort, perform conditional operations, and run calculations in Xpath and XSLT

[22:15] {MikeHelland} This page shows me all pages that are replies (start with "Re:") and every page makred as a high importance

[22:15] {MikeHelland} It will also denote high importance messages, sort the messages by sender, and tell me how many new messages there are

[22:16] {MikeHelland} New replies rather

[22:16] {MikeHelland}

[22:16] {MikeHelland} When we're looking at this, keep in mind that absolutley NO XML was changed

[22:16] {MikeHelland} THis is done 100% IN the Stylesheet

[22:16] {MikeHelland} Any comments before we look at the source?

[22:17] {MikeHelland} None of the source XML was changed, is a better way to phrase it

[22:17] {MikeHelland} The XML in the XSL file changed (the stylesheet is differnet)

[22:18] {MikeHelland} Anyone still following at this point?

[22:18] {BarbaraPeisch} Yup

[22:18] {CarlKarsten} da

[22:18] {DenisChasse} y

[22:18] {MikeHelland} I'll dive into the new XSL

[22:18] {MikeHelland}

[22:18] {MikeHelland} Hi JR

[22:19] {MikeHelland} Right away, there is some new stuff:

[22:19] {MikeHelland} There are {xsl:value-of select="count(root/message[starts-with(subject, 'Re:')])" /} replies waiting for you.

[22:19] {MikeHelland} The Value-Of concept isn't new, but the XPath I use is

[22:20] {MikeHelland} Right off the bat, I'm using an XPath function called Count() which is similar to VFP's COUNT TO and SQL's COunt()

[22:20] {MikeHelland} Inside that, there is this:

[22:20] {Jean-ReneRoy} Salut Denis

[22:20] {MikeHelland} root/message[starts-with(subject, 'Re:')])

[22:20] {Jean-ReneRoy} Hi All

[22:20] {MikeHelland} What teh sqaure brackets mean is that you will be evaluating somethign

[22:21] {MikeHelland} So, in any MESSAGE in teh ROOT node, where the SUBJECT begins with the letters "Re:", we will include in the count

[22:21] {MikeHelland} Starts-With is an XPath function

[22:21] {MikeHelland} Questions?

[22:22] {MikeHelland} Now we do a similar XPath in teh new For-Each

[22:22] {BarbaraPeisch} Can you recommend any good reading on this subject?

[22:22] {MikeHelland} {xsl:for-each select="root/message[starts-with(subject, 'Re:') or @importance='high']"}

[22:22] {MikeHelland} Wrox books

[22:22] {MikeHelland} Just about anything they have is good

[22:22] {BarbaraPeisch} That's what I would have guessed.

[22:22] {MikeHelland} For a complete reference of XSLT and Xpath, check out

[22:22] {MikeHelland} they have full references, which are very helpful

[22:23] {MikeHelland} In any case, there is a new peice to our puzzle:

[22:23] {MikeHelland} @importance='high'

[22:23] {MikeHelland} The "@" signifies that instead of looking at a node, I will look at an attribute

[22:23] {MikeHelland} So, if there is a message that has the attribute "importance", and it equals "high"

[22:24] {MikeHelland} I will be inlcluded in teh "for-each"

[22:24] {MikeHelland} OTherwise, we'll skip it

[22:24] {MikeHelland} Is anyone NOT confused? :-)

[22:24] {BarbaraPeisch} I'm not confused

[22:24] {MikeHelland} Just let me, I'm still movin' on

[22:25] {MikeHelland} Right after the For-Each is this:

[22:25] {MikeHelland} {xsl:sort select="from/displayname" /}

[22:25] {MikeHelland} This specifies that my For Each will be sorted by the name of the sender

[22:25] {MikeHelland} Because now you are in teh For-Each

[22:25] {MikeHelland} ANd teh context was set to root/message

[22:25] {MikeHelland} And there is a from node in message, with a display node

[22:25] {MikeHelland} Here's the source XML,once again

[22:26] {MikeHelland}

[22:26] {MikeHelland} And finally, the LAST little bit of the night (I'll still take questions or try and iron out confusion)

[22:26] {MikeHelland} We get into some more porgramming contructs, we see:

[22:26] {MikeHelland} {xsl:choose}rn {xsl:when test="@importance='high'"}red{/xsl:when}rn {xsl:otherwise}black{/xsl:otherwise}rn {/xsl:choose}

[22:27] {MikeHelland} Choose, when when when otehrwise, is liek DO CASE, CASE{ OTHERWISE in VFP

[22:27] {MikeHelland} XSLT also supports IF too

[22:27] {MikeHelland} But basically, we start a CHoose (DO CASE), and then move right to a "When" (CASE)

[22:28] {MikeHelland} The test attribute holds teh XPath expression, if its true, then whatever is in the when tags is outputted

[22:28] {MikeHelland} Otherwise, it moves on

[22:28] {MikeHelland} The test here is if the "importance" attribute equals high

[22:28] {MikeHelland} If so, red will be sent to teh output

[22:29] {MikeHelland} ANd actually, red is in teh attribute tags, so it will eventually look like:

[22:29] {MikeHelland} {tr bgcolor="red"}

[22:29] {MikeHelland} And thats all I gotta say for tonight

[22:29] {BarbaraPeisch} Wow, great lecture!

[22:29] {MikeHelland} These are actually pretty basic XSLTs, most of teh examples that you find will be based on recusrion in XSLT

[22:30] {MikeHelland} Thats when you have multiple "template" tags lying around, and you set the context, and call teh XSLT again

[22:30] {MikeHelland} It gets pretty nutty!

[22:30] {MikeHelland} Thank Barabara

[22:30] {DenisChasse} Wow thanks alot for that presentation Mike!

[22:30] {RandyJean} Q

[22:30] {MikeHelland} If anyone wants to see a cool use for XSLT, take alook at this

[22:30] {CarlKarsten} good examples, Mike

[22:30] {MikeHelland}

[22:30] {MikeHelland} Go ahead Randy

[22:30] {Vinicio} NIce

[22:31] {MikeHelland} Dink around with my forum for a little bit

[22:31] {MikeHelland} Its all XML/XSLT

[22:31] {RandyJean} What tools are available to make the constructs easyier? (sorry if this was asked already)

[22:31] {MikeHelland} Here's teh cool part, click on "Edit User" and choose a different UI

[22:31] {MikeHelland} OH OH OH OH , Great Question, I can't believe i forgot

[22:31] {CarlKarsten} "There are too many people accessing the Web site at this time."

[22:31] {Jean-ReneRoy} I have basic question Mike!

[22:31] {MikeHelland} Ken Levy emailed me a couple times today

[22:31] {MikeHelland} Hold on

[22:32] {MikeHelland} I noticed this link on the UT home page. Just wanted you to be sure to mention the upcoming VisualXSLT editor/debugger for Visual Studio .NET by ActiveState (28{}). They have a free beta for VS.NET beta 1 now, as well as their own cross-platform IDE called Komodo.

[22:32] {MikeHelland} Next month Microsoft will release VS.NET beta 2 and ActiveState will post a new build of VisualXSLT for VS.NET for beta 2 (with more features). XMLFund paid ActiveState to build this tool, and I wrote the original specification and am the technical advisor for this project.

[22:32] {MikeHelland} Ok, go ahead JR

[22:32] {RandyJean} Cool - thanks!

[22:32] {MikeHelland} Anyways, whats happening on my web form is there is one XSL file controlling all UI for the forum

[22:33] {MikeHelland} And when you turn the combo box, it chooses a different UI to store in your session or forum profile and now everything is routed through that

[22:33] {MikeHelland} THink of the UT could do such things!

[22:33] {MikeHelland} I coudl create myown XSLT file, with my own formating options, and icnlude any filters, sorts or ANYTHING without the UT chanigng at alL!

[22:33] {Jean-ReneRoy} Fom VFP, when we want to use XSL what object do we create?

[22:34] {MikeHelland} I could even change the user interfaceto not even put out HTML output, I could make itput out WAP content, or simirlar :-)

[22:34] {MikeHelland} JR, let me show you :-)

[22:34] {MikeHelland} JR, Look at

[22:35] {MikeHelland} This is VBScirpt code, which is easily VFP code

[22:35] {MikeHelland} YOu create the msxml2.domdocument COM object

[22:35] {MikeHelland} Load your XSL and XML (stylsheet and source) files in to them

[22:35] {MikeHelland} ANd then call, transformNode()

[22:36] {MikeHelland} The result is a text string, which happens to be the result of the XSLT

[22:36] {MikeHelland} Does that make sense?

[22:36] {Jean-ReneRoy} YEs! What exacly do this line response.write(oXML.transformNode(oXSL))

[22:36] {MikeHelland} Does anyone have any other comments or questions?

[22:37] {BarbaraPeisch} Mike, will you be leaving these links active for a while, or at least have them integrated into the transcript for this lecture?

[22:37] {MikeHelland} I'll figure somethign out

[22:37] {MikeHelland} Probably put them right in a Wiki page

[22:37] {MikeHelland} JR, that line does two things

[22:37] {DenisChasse} Putting everything on the wiki page would be very nice. (without links)

[22:38] {MikeHelland} It first tells you that you want to transform your XML data (which is Load()ed in the oXML object) with the XSL Stylsheet (which is loaded in oXSL)

[22:38] {MikeHelland} And then, it uses teh ASP object Response to write the result of teh transformation to the web browser

[22:39] {MikeHelland} Make sense?

[22:39] {MikeHelland} Ok, feel free to email me these questions, once Cindy posts this log, I'll go in and make the exmplaes work right

[22:39] {MikeHelland} Actually, I'm gonna be takingmy server down for a day or two

[22:39] {Jean-ReneRoy} Yes ! Thank you Mike.

[22:40] {MikeHelland} So, if Carl woudl like to host the examples, I can send them to him

[22:40] {CarlKarsten} no prob

[22:40] {CarlKarsten} er wait....

[22:40] {MikeHelland} Ok, you'll get a ZIP :-)

[22:40] {MikeHelland} It needs that MSxml3 installed

[22:40] {CarlKarsten} thats a problem

[22:40] {MikeHelland} And has to use ASP to show the transformation

[22:40] {MikeHelland} You can load msxml3 in side by side mode so it won't damage anythign else

[22:40] {CarlKarsten} I can only do static pages

[22:41] {MikeHelland} Ok, we'll I'll send you the static XML and XSL, and teh results of the transformations

[22:41] {MikeHelland} All static

[22:41] {CarlKarsten} k

[22:41] {MikeHelland} Actually, my computer should be back up tomarrow

[22:42] {MikeHelland} SO anytime after that shoudl be cool, no need to move the files

[22:42] {MikeHelland} Alright, thanks everyone for your patience!

[22:42] {CarlKarsten} well done, Mike

[22:42] {MikeHelland} If you need help,, or Mike (when teh board is fnished)

[22:42] {MikeHelland} or 320-492-0556

[22:42] {DenisChasse} Was this your presentation for DevCon Mike?

[22:42] {MikeHelland} Directline :-)

[22:42] {Jean-ReneRoy} Yes Well done Mike! I like you do do this again some time.

[22:42] {MikeHelland} Denis, nope

[22:43] {MikeHelland} Thank you :-)

[22:43] {Jean-ReneRoy} Ho ! One more quesiton Mike!

[22:43] {MikeHelland} Dev COn presentation is on the Wireless Application protocol

[22:43] {MikeHelland} Ask away

[22:44] {Jean-ReneRoy} I still have you in me list of speaker for future MFUG Metting. Can we talk about it off line}

[22:45] {CarlKarsten} btw - encourage others to come to these lectures. It would be nice to get the attendance up.

[22:45] {MikeHelland} Call me

[22:46] {CarlKarsten} Nothing planned for next week, but I am going to try and make the Devcon gems a doozie

[22:46] {Jean-ReneRoy} Ok! Will do ! What is the time deferences?

[22:46] {CarlKarsten} to mike, time dosn't make a difference

[22:46] {CarlKarsten} ;)

[22:46] {Vinicio} Ok good night everyone, thank you Mike Helland

[22:47] {CarlKarsten} good night Vinicio

[22:47] {MikeHelland} You are welcome!

[22:47] {MikeHelland} As long as you call my Cell Phone (the number I gave out) you can call me anytime

Contributors: Mike Helland, Carl Karsten, Cindy Winegarden
Category Wednesday Night Lectures
( Topic last updated: 2005.01.08 04:21:22 AM )