• Welcome to Valhalla Legends Archive.
 

[XSL] Writing Attribute Values

Started by MyndFyre, November 09, 2004, 09:08 PM

Previous topic - Next topic

MyndFyre

Hi,

I'm working on creating a table-of-contents via XML and XSL-Transform similar to what you see here.  The problem I'm having is that when I try to generate the HTML table of contents, I need to emit a position() call, for example:


<xsl:apply-templates match="position()" />


That in itself is not difficult.  The problem is that I want the position to be within an attribute.  I could say something along the lines of:


<a href="#group_<xsl:apply-templates match="position()" />"><xsl:apply-templates match="Name" /></a>


But that's not well-formed XML (the < within the attribute value in the <a> tag).  So now you have an idea about what I want to do, but I just don't know how to get there.

I have to do a similar thing later when I want to set up the <a name=> part.

Any experience here?  If not I'll keep playing around; that's how I've gotten my XSL thus far.  :)
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

MyndFyre

I figured it out.  Whatever element you want to write an attribute to, you declare it and within nest an <xsl:attribute> element.  For example, I had a couple XSL variables declared, named positionLarge and positionSmall, respectively.  I wanted to generate <a href="#grouppositionLarge_positionSmall" class="nav">NameOfGroup</a> in the output, so:


<a class="nav">
   <xsl:attribute name="href">#group<xsl:value-of select="format-number($positionLarge, '#')" />_<xsl:value-of select="format-number($positionSmall, '#')" /></xsl:attribute>
   <xsl:apply-templates select="Name" />
</a>


positionLarge increments more slowly (on the outside loop) than positionSmall, so it generated something like:

<a class="nav" href="#group1_1">Beginnings</a>
<a class="nav" href="#group1_2">The Council of Chaos</a>
<a class="nav" href="#group1_3">The Lean Times</a>
<a class="nav" href="#group2_1">Division Within</a>

etcetera.

I may write an introductory tutorial to XSL, because I'm finding it so damn useful.  :)
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Banana fanna fo fanna

Argh...can you please explain what it's useful for?

MyndFyre

Quote from: Banana fanna fo fanna on November 11, 2004, 12:19 PM
Argh...can you please explain what it's useful for?

It's useful for transforming raw XML data like you see here into browser-displayable HTML like you see here.

Actually in the XSL version, I don't have attributes in the XML.  But from any page from now on, all I need to do is slightly modify my stylesheet and and it will adapt all the data, as opposed to, when making major layout changes, having to completely rewrite or recode entire paragraphs.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Banana fanna fo fanna

That's terrible! Isn't that what...HTML+RDBMS is for?

MyndFyre

Quote from: Banana fanna fo fanna on November 11, 2004, 02:52 PM
That's terrible! Isn't that what...HTML+RDBMS is for?

But why would I waste expensive RDBMS calls when I can just store the large text data in an easily-accessible format?  The History page isn't going to be changing that often, so why store static content on a (possibly) remote server?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Banana fanna fo fanna

Hrm. I was under the impression you were querying the XML on each hit.

Still...when I see you've defined a custom paragraph tag, I get worried.

MyndFyre

Quote from: Banana fanna fo fanna on November 11, 2004, 07:24 PM
Hrm. I was under the impression you were querying the XML on each hit.

I am querying the XML on each hit.  But XML + XML = faster than retrieve DB records + iterate over DB records. :P
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Banana fanna fo fanna