|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: super basic xsl question
Jeb,
At 11:58 AM 1/13/2005, you wrote: Then I thought fiddling with the 'select' expr in the value-of tag would do it, but I can't figure out if there's a magical combination of XPath slang that means, "whatever the hell is below here, be it tags or text, i want them". xsl:value-of copies the string value of whatever it selects to the result. The string value of a node is the concatenation of string values of its text node descendants, which is what accounts for what you're seeing. As JBryant just said, to copy an entire subtree (not just the context node) from source to result, xsl:copy-of is the thing. But the bit of XPath slang you ultimately will want is xsl:apply-templates. This says "process what I'm selecting by finding templates to match, and applying them". This way, you could not only copy that bit mixing text nodes with <a> elements, but you could also transform the <a> elements. In this case you might not have to do that (they are already what you want) -- but soon you will. This is the heart of the XSLT processing model, and hence of XSLT. So, using something like your example: source: <xmlroot> <child>some text</child> <child><link href="">a link</link> to something</child> </xmlroot> result: <ul> <li>some text</li> <li><a href="">a link</a> to something</li> </ul> try:
<xsl:template match="xmlroot">
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template><xsl:template match="child">
<li>
<xsl:apply-templates/>
</li>
</xsl:template><xsl:template match="link">
<a href="{@href}">
<xsl:apply-templates/>
</a>
</xsl:template>Once you understand what this does and why (the first part is a question you can ask your processor), you'll be set on the straight and narrow path to XSLT mastery. Cheers, Wendell
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








