草庐IT

xml - 将 Head 部分存储在 Coldfusion 中,无需在 XSL 中进行硬编码

coder 2024-07-01 原文

我正在尝试将我的 XSLT 1.0 的这一部分从使用元标记进行硬编码转换为以防将来我想更改它们。有没有办法显示包含样式表、关键字和描述的元标记,而不是在 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">&#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>

最佳答案

您可以定义一个模板来匹配您要生成的元素<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>  

关于xml - 将 Head 部分存储在 Coldfusion 中,无需在 XSL 中进行硬编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20030069/

有关xml - 将 Head 部分存储在 Coldfusion 中,无需在 XSL 中进行硬编码的更多相关文章

  1. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  2. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  3. ruby - 用逗号、双引号和编码解析 csv - 2

    我正在使用ruby​​1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\

  4. ruby-on-rails - 如何从 format.xml 中删除 <hash></hash> - 2

    我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为

  5. jquery - 我的 jquery AJAX POST 请求无需发送 Authenticity Token (Rails) - 2

    rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送

  6. C# 到 Ruby sha1 base64 编码 - 2

    我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha

  7. ruby - Rack:如何将 URL 存储为变量? - 2

    我正在编写一个简单的静态Rack应用程序。查看下面的config.ru代码:useRack::Static,:urls=>["/elements","/img","/pages","/users","/css","/js"],:root=>"archive"map'/'dorunProc.new{|env|[200,{'Content-Type'=>'text/html','Cache-Control'=>'public,max-age=6400'},File.open('archive/splash.html',File::RDONLY)]}endmap'/pages/search.

  8. ruby-on-rails - 为什么在 Rails 5.1.1 中删除了 session 存储初始化程序 - 2

    我去了这个website查看Rails5.0.0和Rails5.1.1之间的区别为什么5.1.1不再包含:config/initializers/session_store.rb?谢谢 最佳答案 这是删除它的提交:Setupdefaultsessionstoreinternally,nolongerthroughanapplicationinitializer总而言之,新应用没有该初始化器,session存储默认设置为cookie存储。即与在该初始值设定项的生成版本中指定的值相同。 关于

  9. ruby-on-rails - 有没有一种工具可以在编码时自动保存对文件的增量更改? - 2

    我最喜欢的Google文档功能之一是它会在我工作时不断自动保存我的文档版本。这意味着即使我在进行关键更改之前忘记在某个点进行保存,也很有可能会自动创建一个保存点。至少,我可以将文档恢复到错误更改之前的状态,并从该点继续工作。对于在MacOS(或UNIX)上运行的Ruby编码器,是否有具有等效功能的工具?例如,一个工具会每隔几分钟自动将Gitcheckin我的本地存储库以获取我正在处理的文件。也许我有点偏执,但这点小保险可以让我在日常工作中安心。 最佳答案 虚拟机有些人可能讨厌我对此的回应,但我在编码时经常使用VIM,它具有自动保存功

  10. c - Ruby - 源代码 - 编码风格 - 2

    查看Ruby代码,它具有以下proc_arity:staticVALUEproc_arity(VALUEself){intarity=rb_proc_arity(self);returnINT2FIX(arity);}更多的是C编码风格问题,但为什么staticVALUE在单独的一行而不是像这样的:staticVALUEproc_arity(VALUEself) 最佳答案 它来自UNIX世界,因为它有助于轻松grep函数的定义:$grep-n'^proc_arity'*.c或使用vim:/^proc_arity

随机推荐