Umbraco XSLT - 检索节点“pageImage”;上市时

发布于 2024-09-09 02:31:47 字数 4650 浏览 5 评论 0原文

我的网站上有一个新闻页面,其中列出了宏中的所有子页面(新闻文章)。

每个子页面都有一个图像(别名 pageImage)

我有以下 XSLT 代码,但它不起作用:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxml="urn:schemas-microsoft-com:xslt" 
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:template match="/">

<!-- The fun starts here -->
<ul id="reports">
<xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
<xsl:sort select="@createDate" order="descending" />
    <li>
        <img>
            <xsl:attribute name="src">
                <xsl:text>/umbraco/ImageGen.ashx?image=</xsl:text>
                <xsl:value-of select="umbraco.library:GetMedia(data[@alias='pageImage'],'true')/data[@alias='umbracoFile']"/>
                <xsl:text>&amp;width=125&amp;height=125&amp;constrain=true&amp;pad=true&amp;BgColor=white&amp;transparent=false</xsl:text>
            </xsl:attribute>
            <xsl:attribute name="alt">
                <xsl:value-of select="something"/>
            </xsl:attribute>
        </img>
        <h2><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></h2>
        <p class="date"><xsl:value-of select="data [@alias = 'date']" disable-output-escaping="yes"/></p>
        <p>Mauris sit amet augue ut felis blandit placerat. Sed tempus gravida libero. Donec placerat lacus 
        eget neque. Mauris sit amet augue ut felis blandit placerat. Sed tempus gravida libero.</p>
        <p><a><img src="images/pdf.gif" alt="Download/view PDF" align="left" /> Download/View PDF</a> - 82kb</p>
    </li>
</xsl:for-each>
</ul>

</xsl:template>

</xsl:stylesheet>

它给我的错误是:

Error occured

System.OverflowException: Value was either too large or too small for an Int32. 
at System.Convert.ToInt32(Double value) 
at System.Double.System.IConvertible.ToInt32(IFormatProvider provider) 
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) 
at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType) 
at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args) 
at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) 
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter) 
at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results) 
at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results) 
at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results) 
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging) in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\presentation\umbraco\webservices\codeEditorSave.asmx.cs:line 124

有人知道出了什么问题吗?我知道这与 行,就像我硬编码图像 URL 一样,它工作得很好。

谢谢!

I've got a news page on my site, which lists all the subpages (news articles) in a macro.

Each of the subpages has an image (alias pageImage)

I've got the following XSLT code, but It's not working:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxml="urn:schemas-microsoft-com:xslt" 
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:template match="/">

<!-- The fun starts here -->
<ul id="reports">
<xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
<xsl:sort select="@createDate" order="descending" />
    <li>
        <img>
            <xsl:attribute name="src">
                <xsl:text>/umbraco/ImageGen.ashx?image=</xsl:text>
                <xsl:value-of select="umbraco.library:GetMedia(data[@alias='pageImage'],'true')/data[@alias='umbracoFile']"/>
                <xsl:text>&width=125&height=125&constrain=true&pad=true&BgColor=white&transparent=false</xsl:text>
            </xsl:attribute>
            <xsl:attribute name="alt">
                <xsl:value-of select="something"/>
            </xsl:attribute>
        </img>
        <h2><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></h2>
        <p class="date"><xsl:value-of select="data [@alias = 'date']" disable-output-escaping="yes"/></p>
        <p>Mauris sit amet augue ut felis blandit placerat. Sed tempus gravida libero. Donec placerat lacus 
        eget neque. Mauris sit amet augue ut felis blandit placerat. Sed tempus gravida libero.</p>
        <p><a><img src="images/pdf.gif" alt="Download/view PDF" align="left" /> Download/View PDF</a> - 82kb</p>
    </li>
</xsl:for-each>
</ul>

</xsl:template>

</xsl:stylesheet>

And the error it's giving me is:

Error occured

System.OverflowException: Value was either too large or too small for an Int32. 
at System.Convert.ToInt32(Double value) 
at System.Double.System.IConvertible.ToInt32(IFormatProvider provider) 
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) 
at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType) 
at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args) 
at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) 
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter) 
at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results) 
at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results) 
at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results) 
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging) in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\presentation\umbraco\webservices\codeEditorSave.asmx.cs:line 124

Anybody have any idea what's going wrong? I know it's something to do with the <xsl:value-of select="umbraco.library:GetMedia(data[@alias='pageImage'],'true')/data[@alias='umbracoFile']"/> line as if I hardcode an image URL, it works fine.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在梵高的星空下 2024-09-16 02:31:47

umbraco.library:GetMedia 调用需要一个整数作为第一个论点。当 data[@alias='pageImage'] 的值转换为 Int32 时,似乎会发生该错误。

The umbraco.library:GetMedia call expects an integer as the first argument. The error seems to occur when the value of data[@alias='pageImage'] is converted to Int32.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文