2012-03-22 171 views
2
<?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:variable name="MediaNodeId" select="./@id"/> 
<!-- Input the documenttype you want here --> 
<xsl:variable name="level" select="1"/> 

<xsl:template match="/"> 

<!-- The fun starts here --> 
<ul class=" menu nav"> 
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> 
    <li> 
    <a href="{umbraco.library:NiceUrl(@id)}"> 
     <xsl:value-of select="@nodeName"/> 
    </a> 
    <xsl:if test="count(./child::*[@isDoc and string(umbracoNaviHide) != '1']) &gt; 0"> 
     <ul> 
     <xsl:for-each select="./child::*[@isDoc and string(umbracoNaviHide) != '1']"> 
      <li> 
      <xsl:choose> 

       <xsl:when test="name()= 'Link' "> 

       <xsl:if test="linkUrl!=''"> 
        <a href="{umbraco.library:GetMedia(linkUrl, 0)/umbracoFile}" target="_blank"> 
        <xsl:value-of select="@nodeName"/></a> 
       </xsl:if> 
       </xsl:when>   

       <xsl:otherwise> 
       <a href="{umbraco.library:NiceUrl(@id)}"> 
       <xsl:value-of select="@nodeName"/></a> 
       </xsl:otherwise> 

      </xsl:choose> 

      <xsl:if test="count(./child::*[@isDoc and string(umbracoNaviHide) != '2']) &gt; 0"> 
     <ul> 
     <xsl:for-each select="./child::*[@isDoc and string(umbracoNaviHide) != '2']"> 
      <li> 
      <a href="{umbraco.library:NiceUrl(@id)}"> 
       <xsl:value-of select="@nodeName"/> 
      </a> 
      </li> 
     </xsl:for-each> 
     </ul> 
    </xsl:if> 
      </li> 
     </xsl:for-each> 
     </ul> 
    </xsl:if> 
    </li> 
</xsl:for-each> 
</ul> 
<div id="jflanguageselection"><div class="rawimages"><span id="active_language"><a href="http://www.hooymans-duivensport.nl/nl"><img src="/images/nl.gif" alt="Nederlands (NL-nl)" title="Nederlands (NL-nl)" /></a></span><span><a href="http://www.hooymans-duivensport.nl/en"><img src="/images/en.gif" alt="English (United Kingdom)" title="English (United Kingdom)" /></a></span></div></div> 
</xsl:template> 

</xsl:stylesheet> 

我需要在pdf文件的菜單中創建一個鏈接我得到這個錯誤。從菜單鏈接到PDF

時出錯

System.OverflowException:值被太大或太小,一個Int32。 在System.Convert.ToInt32(雙精度值) 在System.Convert.ChangeType(對象值,類型conversionType,的IFormatProvider提供商) 在System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType XMLTYPE,對象的值,類型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 System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument,XmlResolver dataSources,XsltArgumentList argumentList,XmlWriter writer) at System.Xml.Xsl.XslCompiledTransform .Transform(IXPathNavigable輸入,XsltArgumentList argumentsmen TS,TextWriter的結果) 在umbraco.presentation.webservices.codeEditorSave.SaveXslt(字符串文件名,字符串使用oldName,字符串fileContents,布爾ignoreDebugging)

+0

你知道確切的行/塊拋出的錯誤? – 2012-03-22 15:43:42

回答

1

這個錯誤在XSLT解析常見於一把umbraco的解析器假定一些你數據可能爲空/空,實際上可能會[總是]分配。

訣竅是找到罪魁禍首的代碼行,並附上一個測試空白如果塊。

例如,它可以是或可以不是這條線,儘管其相當通常與@idNiceUrl()發生:

<xsl:otherwise> 
    <xsl:if test="@id != ''"> 
     <a href="{umbraco.library:NiceUrl(@id)}"> 
      <xsl:value-of select="@nodeName"/> 
     </a> 
    </xsl:if> 
</xsl:otherwise> 

的誤差很可能從GetMedia()NiceUrl() 到出現呼叫,因爲他們需要一個Int32類型的參數傳遞,但我可以看到你已經把你的GetMedia()調用放在一個if塊中。

http://our.umbraco.org/forum/developers/xslt/30131-Loading-Xslt-Value-was-either-too-large-or-too-small-for-an-Int32-

http://our.umbraco.org/forum/developers/xslt/3102-Using-niceurl-Value-was-either-too-large-or-too-small-for-an-Int32-

+0

在循環瀏覽頁面節點的情況下,@id永遠不會爲空,因爲所有INode對象都必須具有id屬性。 – Digbyswift 2012-03-22 17:58:46

+0

@Digbyswift - 你甚至讀過我的回答嗎?你知道我用這行代碼作爲_example_來證明另一點嗎?有時你需要把錯誤行放在IF塊中以使其工作。我甚至說它可能不是這個特定的代碼行。你說得對,因爲所有_page_節點都必須包含一個ID屬性,但解析器不會假設這一點,它會根據_actual_ XML進行假設,而不是所有_actual_節點都有一個ID(例如Umbraco屬性)。嘗試在此[PasteBin](http://pastebin.com/Tyw0Zust)上執行XSLT以查看我的意思。 – 2012-03-23 01:39:48

+0

是的,我做了,你的答案應該更清楚。通過在Umbraco標記的帖子中使用@id和NiceUrl()作爲示例,您將爲後續用戶造成混淆。 – Digbyswift 2012-03-23 09:23:26