A slightly off-topic question regarding XSLT (I am extending the XHTML-to-LateX template).
I have the following XHTML markup:
<div class="versionhistory"> <div class="version" v="v1.0" d="2006-05-04" a="SBR">Change description v1.0</div> <div class="version" v="v1.1" d="2006-05-05" a="SBR">Change description v1.1</div> <div class="version" v="v2.0" d="2006-05-06" a="SBR">Change description v2.0</div> </div>
and would like to read the value of attribute "d".
Now, with something like
<xsl:template name="get-version-date"> <xsl:param name="vers" /> <xsl:value-of select="//div[@class='version'][@v=$vers]" /> </xsl:template>
I can get easily the value of a specific "version div", such as the string "Change description v1.0". But how do I write the select statement to get "d" of a specific version instead? Or similarly, what is the path to read the attribute "content" of a meta tag such as
<meta name="documentclass" content="wtdocument" />
with something like
<xsl:template name="get-meta-value"> <xsl:param name="tag-name" /> <xsl:value-of select="/html/head/meta[@name=$tag-name] (*???*)" /> </xsl:template>
Thanks for any help!
With regards - Stefan
OK, you're stretching my ancient XSLT recollections, but what you've written just makes me scratch my head!
Try something like the following stylesheet (output is below): with any luck it illustrates a way to achieve what you're after. [[The stuff inside the square brackets where "dvalue" is found should be read as "given"; hence the XPath expression reads "the value of the @d attribute of the div element which has a "class" attribute of "version" and a "v" attribute found below as $vers.]] The other thing worth mentioning is that the "get-version-date" template is being called with the version number, but you still need to declare "vers" as a parameter in the declaration of the template.
I hope this is of some use!
Cheers, Paul
======================================================================= <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="get-version-date"> <xsl:param name="vers"></xsl:param> <xsl:param name="dvalue"><xsl:value-of select="//div[@class='version' and @v=$vers]/@d"/></xsl:param> Date string is <xsl:value-of select="$dvalue"/> to be sure. </xsl:template>
<xsl:template match="//div[@class='version']"> <xsl:call-template name="get-version-date"> <xsl:with-param name="vers"> <xsl:value-of select="./@v"/> </xsl:with-param> </xsl:call-template> </xsl:template>
</xsl:stylesheet>
======================================================================= Output is...
<?xml version="1.0" encoding="utf-8"?>
Date string is 2006-05-04 to be sure.
Date string is 2006-05-05 to be sure.
Date string is 2006-05-06 to be sure.
Stefan Brantschen <sbr@...> writes:
<xsl:template name="get-version-date"> <xsl:param name="vers" /> <xsl:value-of select="//div[ <at> class='version'][ <at> v=$vers]" /> </xsl:template>
I can get easily the value of a specific "version div", such as the string "Change description v1.0". But how do I write the select statement to get "d" of a specific version instead?
Stefan -
I think
<xsl:value-of select="//div[@class='version'][@v=$vers]/@d" />
may do it?
Quentin
Thanks to Paul and Quentin. To summarize, here's the snippet:
This is the XSLT template to get the value of an XHTML meta tag's "content" attribute:
<xsl:template name="get-meta-value"> <xsl:param name="tag-name" /> <xsl:value-of select="/html/head/meta[@name=$tag-name]/@content" /> </xsl:template>
...that is, to read from this XHTML example markup:
<html> <head> <meta name="author" content="SBR" /> <meta name="classoptions" content="wtzg, english, confidential" /> <meta name="copyrightyear" content="2006" /> <meta name="documentclass" content="wtdocument" /> </head> <body </body> </html>
the values of "documentclass" ("wtdocument") and "classoptions" ("wtzg, english, confidential") for a LaTeX doc as in
<xsl:template name="doc-class"> xsl:text\documentclass[</xsl:text> <xsl:call-template name="get-meta-value"> <xsl:with-param name="tag-name"> xsl:textclassoptions</xsl:text> </xsl:with-param> </xsl:call-template> xsl:text]{</xsl:text> <xsl:call-template name="get-meta-value"> <xsl:with-param name="tag-name"> xsl:textdocumentclass</xsl:text> </xsl:with-param> </xsl:call-template> xsl:text}</xsl:text> <xsl:value-of select="$newline" /> </xsl:template>
to get "\documentclass[wtzg, english, confidential]{wtdocument}"
I hope I have copied everything OK... :-)
Thanks and regards - Stefan
On 22 May 2006, at 16:08, Quentin Stafford-Fraser wrote:
Stefan Brantschen <sbr@...> writes:
<xsl:template name="get-version-date"> <xsl:param name="vers" /> <xsl:value-of select="//div[ <at> class='version'][ <at> v= $vers]" /> </xsl:template>
I can get easily the value of a specific "version div", such as the string "Change description v1.0". But how do I write the select statement to get "d" of a specific version instead?
Stefan -
I think
<xsl:value-of select="//div[@class='version'][@v=$vers]/@d" />
may do it?
Quentin