gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 02:35:38 28 4
gpt4 key购买 nike

我正在尝试将我的 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com