如何在 Symphony CMS 中的 XML 中使用 XSL
How to use a XSL inside an XML in Symphony CMS
我有一个名为 Products
的部分,其中每个产品都由 Text Input
和 Multilingual Text Box
定义。我已经创建了 100 多种具有自定义描述的产品。在某些时候,我需要将当前年份放在 Multilingual Text Box
:
Lorem ipsum dolor <xsl:value-of select="$this-year" /> ipsum <a href="{$root}">Link to root</a>
给出:
'Long Description' contains invalid XML. The following error was returned: loadXML(): Namespace prefix xsl on value-of is not defined in Entity
或者我想打印来自数据源的数据:
Lorem ipsum
<xsl:variable name="products" select="/data/products" />
<xsl:for-each select="$products">
//... do other XSL stuff in XML
</xsl:for-each>
这当然也会导致错误。
请注意我是Symphony/XSLT的初学者,有些概念我还不是很理解。
Symphony 社区帮助我解决了这个问题,所以我只引用 jonmifsud:
The easiest way to do that would be using what’s called the XSLT ninja technique. Simplest way (...) would be to create html tags which are to be replaced. For example we can ask him to input <this-year/>
in the text where you want this year variable to appear which means when you output text you are using <xsl:apply-template select=‘your-text’ mode=‘html'/>
. Now the trick with the XSLT would be the following: you will need to match the new “tag” you created for your variable and replace it with the values you want
例子
<xsl:template match="this-year" mode="html">
<xsl:value-of select="/data/params/this-year">
</xsl:template>
<xsl:template match="*" mode="html">
<xsl:element name="{name()}">
<xsl:apply-templates select="* | @* | text()" mode="html"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*" mode="html">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
这种方法几乎是无限的。
我有一个名为 Products
的部分,其中每个产品都由 Text Input
和 Multilingual Text Box
定义。我已经创建了 100 多种具有自定义描述的产品。在某些时候,我需要将当前年份放在 Multilingual Text Box
:
Lorem ipsum dolor <xsl:value-of select="$this-year" /> ipsum <a href="{$root}">Link to root</a>
给出:
'Long Description' contains invalid XML. The following error was returned: loadXML(): Namespace prefix xsl on value-of is not defined in Entity
或者我想打印来自数据源的数据:
Lorem ipsum
<xsl:variable name="products" select="/data/products" />
<xsl:for-each select="$products">
//... do other XSL stuff in XML
</xsl:for-each>
这当然也会导致错误。
请注意我是Symphony/XSLT的初学者,有些概念我还不是很理解。
Symphony 社区帮助我解决了这个问题,所以我只引用 jonmifsud:
The easiest way to do that would be using what’s called the XSLT ninja technique. Simplest way (...) would be to create html tags which are to be replaced. For example we can ask him to input
<this-year/>
in the text where you want this year variable to appear which means when you output text you are using<xsl:apply-template select=‘your-text’ mode=‘html'/>
. Now the trick with the XSLT would be the following: you will need to match the new “tag” you created for your variable and replace it with the values you want
例子
<xsl:template match="this-year" mode="html">
<xsl:value-of select="/data/params/this-year">
</xsl:template>
<xsl:template match="*" mode="html">
<xsl:element name="{name()}">
<xsl:apply-templates select="* | @* | text()" mode="html"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*" mode="html">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
这种方法几乎是无限的。