我试图将我的XSLT 1.0的这部分转换为使用meta标签进行硬编码,以防我以后想要更改它们。有没有办法在ColdFusion中显示包含样式表,关键字和描述的元标记?
我已经尝试过并且几乎可以使用样式表,但它只显示在<html>
之上或</html>
之下而不是<head>
之内,这是我需要它去的地方对于所有这些。
关于如何以这种方式显示的任何建议?
CFM
**
<cfset MyXmlFile = Expandpath("events.xml")>
<cffile action="READ" variable="xmlInput" file="#MyXmlFile#">
<cfset MyXmlFile = Expandpath("events.xsl")>
<cffile action="READ" variable="xslInput" file="#MyXmlFile#">
<cfset xslParam = StructNew() >
<cfset xslParam["pram"] = "#url.pram#" >
<cfset xmlOutput = XMLTransform(xmlInput, xslInput, xslParam)>
<!--- data is output --->
<cfcontent type="text/html" reset="true" /><!DOCTYPE html>
<cfoutput>
<cfset style='<link rel="stylesheet" type="text/css" href="stylesheet.css">' />
#style#
#xmloutput#
</cfoutput>
**
XSLT
<xsl:element name="meta"><xsl:attribute name="name">description</xsl:attribute><xsl:attribute name="content">Listings of all events</xsl:attribute></xsl:element>
<xsl:element name="meta"><xsl:attribute name="name">keywords</xsl:attribute><xsl:attribute name="content">events, event, music, help, information</xsl:attribute></xsl:element>
<xsl:element name="link"><xsl:attribute name="rel">icon</xsl:attribute><xsl:attribute name="href">images/favicon.ico</xsl:attribute><xsl:attribute name="type">image/x-icon</xsl:attribute></xsl:element>
<xsl:element name="link"><xsl:attribute name="rel">shortcut icon</xsl:attribute><xsl:attribute name="href">images/favicon.ico</xsl:attribute><xsl:attribute name="type">image/x-icon</xsl:attribute></xsl:element>
<xsl:element name="link"><xsl:attribute name="rel">stylesheet</xsl:attribute><xsl:attribute name="type">text/css</xsl:attribute><xsl:attribute name="href">stylesheet.css</xsl:attribute></xsl:element>
HTML 热门部分
<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="stylesheet.css"> <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="Listings of all events">
<meta name="keywords" content="events, event, music, help, information">
<link rel="icon" href="images/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<title>London Comic Con</title>
</head>
<body>
XML 示例
<?xml version="1.0" encoding="ISO-8859-1"?>
<events
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="events.xsd">
<venue id="01" vtitle="ExCeL Exhibition Centre" location="London" telephone="0844 448 7600">
<about>The ExCel Exhibition Centre was opened in November 2000 and was built by Sir Robert MacAlpine. The venue was most recently bought over acquired by the Abu Dhabi National Exhibitions Company in 2008. Phase II was completed on 1 May 2010. This expansion created The International Convention Centre London (ICC London) adding to ExCeL's event space, as well as further meeting space and banqueting facilities.</about>
<event name="London Comic Con" date="2013-10-12">
<image>images/MCM1.jpg</image><attribute>London Anime Event</attribute>
<description>A convention for all things Anime, video games and Japanese culture.</description>
<keywords>events, event, music, help, information</keywords>
<ticket_price type="adult" status="none">£18.00</ticket_price>
<ticket_price type="child" status="available">£8.00</ticket_price>
<ticket_price type="junior" status="available">£0.00</ticket_price>
<email>london@mcmexpo.net</email>
</event>
答案 0 :(得分:2)
您可以定义模板以匹配要为其生成<meta>
元素的元素,并使用其属性构造相应的<meta>
元素。
此示例使用带有属性值模板的元素文字:
<xsl:template match="description | keywords" mode="meta">
<meta name="{local-name()}" content="{.}"/>
</xsl:template>
应用于样式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="/">
<html>
<xsl:call-template name="head"/>
<!--body stuff goes here-->
</html>
</xsl:template>
<xsl:template name="head">
<head>
<xsl:apply-templates select="/events/venue/event/*" mode="meta"/>
<link rel="icon" href="images/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" type="text/css" href="stylesheet.css"/>
</head>
</xsl:template>
<!--template to match the elements that you want to produce meta elements for-->
<xsl:template match="description | keywords" mode="meta">
<meta name="{local-name()}" content="{.}"/>
</xsl:template>
<!--for all other elements in this mode, do nothing -->
<xsl:template match="*" mode="meta"/>
</xsl:stylesheet>
答案 1 :(得分:0)
我通过在ColdFusion文件中添加创建cfhtmlhead
部分来完成这项工作。每the documentation:
使用此标记嵌入JavaScript代码或放置其他HTML 标记,例如HTML页面标题中的元,链接,标题或基础。
CFM - 示例
<cfhtmlhead text='<link rel="stylesheet"
type="text/css"
href="stylesheet.css">#chr(13)##chr(10)#'>