Xml 将Head部分存储在Coldfusion中,而不在XSL中进行硬编码

Xml 将Head部分存储在Coldfusion中,而不在XSL中进行硬编码,xml,xslt,coldfusion,xslt-1.0,meta-tags,Xml,Xslt,Coldfusion,Xslt 1.0,Meta Tags,我正在尝试将XSLT1.0的这一部分从使用元标记硬编码转换为元标记,以防将来需要更改它们。是否有一种方法可以在ColdFusion中显示包含样式表、关键字和描述的元标记 我已经尝试过让它几乎与样式表一起工作,但它只在上方或下方显示,而不是在内部,这正是我需要它的地方 有没有关于我应该如何用这种方式展示的建议 CFM ** #风格# #XML输出# ** XSLT <xsl:element name="meta"><xsl:attribute name="name">

我正在尝试将XSLT1.0的这一部分从使用元标记硬编码转换为元标记,以防将来需要更改它们。是否有一种方法可以在ColdFusion中显示包含样式表、关键字和描述的元标记

我已经尝试过让它几乎与样式表一起工作,但它只在
上方或
下方显示,而不是在
内部,这正是我需要它的地方

有没有关于我应该如何用这种方式展示的建议

CFM

**


#风格#
#XML输出#
**

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>
描述所有事件的列表
关键词事件、事件、音乐、帮助、信息
iconimages/favicon.icoimage/x-icon
快捷方式iconimages/favicon.icoimage/x-icon
stylesheettext/cssstylesheet.css
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">&#163;18.00</ticket_price>
        <ticket_price type="child" status="available">&#163;8.00</ticket_price>
        <ticket_price type="junior" status="available">&#163;0.00</ticket_price>
        <email>london@mcmexpo.net</email>
    </event>

ExCel展览中心于2000年11月开放,由Robert MacAlpine爵士建造。该场馆最近于2008年被阿布扎比国家展览公司收购。第二阶段于2010年5月1日完成。扩建后的伦敦国际会议中心(ICC London)增加了ExCeL的活动空间,以及更多的会议空间和宴会设施。
images/MCM1.jpgLondon动漫活动
动漫、电子游戏和日本文化的一个公约。
事件、事件、音乐、帮助、信息
£18
£8
£0
london@mcmexpo.net

您可以定义一个模板来匹配要为其生成
元素的元素,并使用其属性构造相应的
元素

此示例将元素文字与属性值模板一起使用:

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

我通过在ColdFusion文件中添加一个
cfhtmlhead
部分来完成这项工作。Per:

使用此标记嵌入JavaScript代码或放置其他HTML 标记,例如HTML页面标题中的meta、link、title或base

CFM-示例

<cfhtmlhead text='<link rel="stylesheet" 
     type="text/css" 
     href="stylesheet.css">#chr(13)##chr(10)#'>


您是否在询问是否可以从正在转换的源XML中获取描述或关键字的值?如果是这样的话,答案是肯定的,但是如果您发布了一个正在转换的XML示例,这将非常有用。如果您想知道是否可以引用外部XML配置或XSLT的其他部分,答案也是肯定的。请更具体地说明您希望从何处获取这些值,并且有人可以建议实现解决方案的方法。这是一个示例,我希望所有这些数据从XML链接到XSLT,然后拉入XSLT,我看不出您将如何对带有图标和样式表的元标记执行此操作,您希望
中的
中的内容以及
中的
中的内容?您是在为每个事件生成一个HTML页面,还是在为每个
创建一个页面,并且希望将
中的内容连接起来?是的,对于描述和关键字,这与其他元标记和样式表相同。我正在使用带有参数的ColdFusion生成从列表页面选择的事件,但我知道如何执行此操作。感谢您抽出时间,但这种方式对我不起作用。我已经改变了问题来解释我是如何做到这一点的,因为另一种方法不起作用谢谢你的时间,但这种方法对我不起作用。我改变了问题,解释了我是如何尝试这样做的,因为另一种方法不起作用
<cfhtmlhead text='<link rel="stylesheet" 
     type="text/css" 
     href="stylesheet.css">#chr(13)##chr(10)#'>