Page 1 of 1

Using IF statements for differentiating between several xhtml metatags

Posted: Fri Feb 24, 2012 8:10 pm
by LMCGIB10
Hi,

In my source xhtml I have three metatags in the head as follows:

Code: Select all


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>blah blah</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="keywords" content="keywordone, keywordtwo, keywordthree" />

<meta name="revised" content="2010-2-15T14:50:7+0"/>
...
</head>
In my xslt, I currently have

Code: Select all


    <xsl:template match="html:meta"
<dc:modified>
<xsl:value-of select="@content"/>
</dc:modified>
which returns

Code: Select all


<dc:modified>text/html; charset=UTF-8</dc:modified>
<dc:modified>keywordone, keywordtwo, keywordthree</dc:modified>
<dc:modified>2010-2-15T14:50:7+0</dc:modified>
However I would like the follwing

Code: Select all


<dc:content>text/html; charset=UTF-8</dc:content>
<dc:description>keywordone, keywordtwo, keywordthree</dc:description>
<dc:modified>2010-2-15T14:50:7+0</dc:modified>
So I thought about using <xsl:if>, but really don't know the syntax for working it through.

I would like to implement something like:

Code: Select all


If
@meta, content=date format
then
<dc:modified>
<xsl:value-of select=".">
<dc:modified>
else if
@meta, content=keywordone, ...
then
<dc:description>
<xsl:value-of select=".">
<dc:modified>
else
@meta, content=text/html
then
<dc:content>
<xsl:value-of select=".">
<dc:content>
Any suggestions or help would be excellent.
Kind Regards

Lewis

Re: Using IF statements for differentiating between several xhtml metatags

Posted: Mon Feb 27, 2012 1:32 pm
by adrian
Hi,

It's simple, use a more explicit XPath match for each type of meta. The order is also important, the most generic match must be used at the end:

Code: Select all


    <xsl:template match="html:meta[@name='keywords']"
<dc:description>
<xsl:value-of select="@content"/>
</dc:description>

<xsl:template match="html:meta[@name='revised']"
<dc:modified>
<xsl:value-of select="@content"/>
</dc:modified>

<xsl:template match="html:meta"
<dc:content>
<xsl:value-of select="@content"/>
</dc:content>
Regards,
Adrian

Re: Using IF statements for differentiating between several xhtml metatags

Posted: Mon Feb 27, 2012 4:59 pm
by LMCGIB10
And again Adrian, thank you very much. You're help has been great. I'm not only making progress but learning as well.

Thank you :D