Using IF statements for differentiating between several xhtml metatags

Here should go questions about transforming XML with XSLT and FOP.
LMCGIB10
Posts: 6
Joined: Wed Feb 15, 2012 5:45 pm

Using IF statements for differentiating between several xhtml metatags

Post 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
adrian
Posts: 2879
Joined: Tue May 17, 2005 4:01 pm

Re: Using IF statements for differentiating between several xhtml metatags

Post 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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
LMCGIB10
Posts: 6
Joined: Wed Feb 15, 2012 5:45 pm

Re: Using IF statements for differentiating between several xhtml metatags

Post 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
Post Reply