我試圖使用Muenchian分組以分層方式顯示公司策略文檔。策略文檔全部添加到SharePoint,並使用語言,類別和文檔類型進行標記。然後我使用這個創建的XML。將兄弟節點作爲一個用於XSLT Muenchian分組
我需要從2個合併列表中獲取數據。 SharePoint的工作方式,我的XML看起來像這樣(每個SharePoint列表都有一個Rows元素):我不得不簡化它以移除數百個SP在添加到stackoverflowsize限制時添加的屬性,但結構是準確的。
<dsQueryResponse>
<Rows>
<Row Title="Testitem" Category="Category 1" Language="English" DocumentType="Content" />
</Rows>
<Rows>
<Row Title="Doc1" Category="Category 1" Language="English" DocumentType="Policy" />
<Row Title="Policy2" Category="Category 2" Language="English" DocumentType="Policy" />
<Row Title="Policy3" Category="Category 1" Language="Nederlands (Dutch)" DocumentType="Form" />
</Rows>
</dsQueryResponse>
當前XSL是這樣的:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:SharePoint="Microsoft.SharePoint.WebControls"
xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
xmlns:agg="http://schemas.microsoft.com/sharepoint/aggregatesource"
xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:ddwrt2="urn:frontpage:internal"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xsl msxsl ddwrt"
ddwrt:oob="true"
>
<xsl:output indent="yes" omit-xml-declaration="yes" />
<xsl:key name="byLANGUAGE" match="/dsQueryResponse/Rows/Row" use="@Language" />
<xsl:key name="byCATEGORY" match="/dsQueryResponse/Rows/Row" use="concat(@Language, '+', @Category)" />
<xsl:template match="/">
<xsl:apply-templates select="/dsQueryResponse/Rows/Row[count(. | key('byLANGUAGE', @Language)[1]) = 1]/@Language">
<xsl:sort select="." order="ascending" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="@Language">
<br /><b>Below you can see all policies in <xsl:value-of select="." /></b><br /><br />
<xsl:variable name="thisLanguage" select="key('byLANGUAGE', .)" />
<xsl:apply-templates select="$thisLanguage[count(. | key('byCATEGORY', concat(@Language, '+', @Category))[1])= 1]/@Category">
<xsl:sort select="." order="ascending" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="@Category">
<br />Category: <xsl:value-of select="." />
<xsl:apply-templates select="key('byCATEGORY', concat(../@Language, '+', .))" />
</xsl:template>
<xsl:template match="/dsQueryResponse/Rows/Row">
<br />Title: <xsl:value-of select="@Title" />
</xsl:template>
</xsl:stylesheet>
和當前結果看起來像這樣(一團糟):
Below you can see all policies in English Category: Category 1 Title: Testitem Category: Category 2 Title: Policy2 Below you can see all policies in English Category: Category 1 Title: Testitem Category: Category 2 Title: Policy2 Below you can see all policies in Nederlands (Dutch) Category: Category 1 Title: Policy3 **My desired output is:** Below you can see all policies in English Category: Category 1 Title: Testitem Title: Doc1 Category: Category 2 Title: Policy2 Below you can see all policies in Nederlands (Dutch) Category: Category 1 Title: Policy3
所以,我似乎獲得了大量的可能是因爲某些事情被調用了兩次,每次行爲元素一次?我是XSL的新手,所以任何幫助,將不勝感激。
========== ========== UPDATE
現在下面的代碼對我的作品在SharePoint(笨重面色選擇語句在技術上不必要的,但我需要他們擺脫非英文字符JQuery的,我已經把在此之上)的:
全部XSLT:
<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:agg="http://schemas.microsoft.com/sharepoint/aggregatesource" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" ddwrt:oob="true">
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:key name="byLANGUAGE" match="/dsQueryResponse/Rows/Row" use="@Language" />
<xsl:key name="byCATEGORY" match="/dsQueryResponse/Rows/Row" use="concat(@Language, '+', @Category)" />
<xsl:template match="/">
<div id="tabs" style="display:none;">
<!--Create tabs-->
<ul>
<xsl:apply-templates select="/dsQueryResponse/Rows/Row[count(. | key('byLANGUAGE', @Language)[2]) = 1]/@Language">
<xsl:sort select="." order="ascending" />
</xsl:apply-templates>
</ul>
<!--Create content-->
<xsl:apply-templates select="/dsQueryResponse/Rows/Row[count(. | key('byLANGUAGE', @Language)[2]) = 1]/@Language" mode="pass2">
<xsl:sort select="." order="ascending" />
</xsl:apply-templates>
</div>
</xsl:template>
<!--Do a first pass to create the tabs -->
<xsl:template match="@Language">
<li>
<xsl:choose>
<xsl:when test=". = 'English'"><xsl:text disable-output-escaping="yes"><a href="#English"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
<xsl:when test=". = 'Bahasa'"><xsl:text disable-output-escaping="yes"><a href="#Bahasa"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
<xsl:when test=". = '簡體中文 (Chinese)'"><xsl:text disable-output-escaping="yes"><a href="#Chinese"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
<xsl:when test=". = 'Nederlands (Dutch)'"><xsl:text disable-output-escaping="yes"><a href="#Dutch"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
<xsl:when test=". = 'Français (French)'"><xsl:text disable-output-escaping="yes"><a href="#French"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
<xsl:when test=". = 'Deutsch (German)'"><xsl:text disable-output-escaping="yes"><a href="#German"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
<xsl:when test=". = 'Italiano (Italian)'"><xsl:text disable-output-escaping="yes"><a href="#Italian"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
<xsl:when test=". = '日本語 (Japanese)'"><xsl:text disable-output-escaping="yes"><a href="#Japanese"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
<xsl:when test=". = '한국의 (Korean)'"><xsl:text disable-output-escaping="yes"><a href="#Korean"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
<xsl:when test=". = 'Polski (Polish)'"><xsl:text disable-output-escaping="yes"><a href="#Polish"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
<xsl:when test=". = 'Português (Portuguese)'"><xsl:text disable-output-escaping="yes"><a href="#Portuguese"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
<xsl:when test=". = 'PyccĸИЙ (Russian)'"><xsl:text disable-output-escaping="yes"><a href="#Russian"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
<xsl:when test=". = 'Castellano (Spanish)'"><xsl:text disable-output-escaping="yes"><a href="#Spanish"></xsl:text><xsl:value-of select="." /><xsl:text disable-output-escaping="yes"></a></xsl:text></xsl:when>
</xsl:choose>
</li>
</xsl:template>
<!--and a second pass to do everything else-->
<xsl:template match="@Language" mode="pass2">
<xsl:choose>
<xsl:when test=". = 'English'"><xsl:text disable-output-escaping="yes"><div id="English"></xsl:text></xsl:when>
<xsl:when test=". = 'Bahasa'"><xsl:text disable-output-escaping="yes"><div id="Bahasa"></xsl:text></xsl:when>
<xsl:when test=". = '簡體中文 (Chinese)'"><xsl:text disable-output-escaping="yes"><div id="Chinese"></xsl:text></xsl:when>
<xsl:when test=". = 'Nederlands (Dutch)'"><xsl:text disable-output-escaping="yes"><div id="Dutch"></xsl:text></xsl:when>
<xsl:when test=". = 'Français (French)'"><xsl:text disable-output-escaping="yes"><div id="French"></xsl:text></xsl:when>
<xsl:when test=". = 'Deutsch (German)'"><xsl:text disable-output-escaping="yes"><div id="German"></xsl:text></xsl:when>
<xsl:when test=". = 'Italiano (Italian)'"><xsl:text disable-output-escaping="yes"><div id="Italian"></xsl:text></xsl:when>
<xsl:when test=". = '日本語 (Japanese)'"><xsl:text disable-output-escaping="yes"><div id="Japanese"></xsl:text></xsl:when>
<xsl:when test=". = '한국의 (Korean)'"><xsl:text disable-output-escaping="yes"><div id="Korean"></xsl:text></xsl:when>
<xsl:when test=". = 'Polski (Polish)'"><xsl:text disable-output-escaping="yes"><div id="Polish"></xsl:text></xsl:when>
<xsl:when test=". = 'Português (Portuguese)'"><xsl:text disable-output-escaping="yes"><div id="Portuguese"></xsl:text></xsl:when>
<xsl:when test=". = 'PyccĸИЙ (Russian)'"><xsl:text disable-output-escaping="yes"><div id="Russian"></xsl:text></xsl:when>
<xsl:when test=". = 'Castellano (Spanish)'"><xsl:text disable-output-escaping="yes"><div id="Spanish"></xsl:text></xsl:when>
</xsl:choose>
<b>Below you can see all policies in <xsl:value-of select="." /></b><br /><br/>
<div class="accordion">
<xsl:variable name="thisLanguage" select="key('byLANGUAGE', .)" />
<xsl:apply-templates select="$thisLanguage[count(. | key('byCATEGORY', concat(@Language, '+', @Category))[2])= 1]/@Category">
<xsl:sort select="." order="ascending" />
</xsl:apply-templates>
</div>
<xsl:text disable-output-escaping="yes"></div></xsl:text>
</xsl:template>
<xsl:template match="@Category">
<h3>
<xsl:value-of select="." />
</h3>
<div class="accordionContent">
<xsl:apply-templates select="key('byCATEGORY', concat(../@Language, '+', .))"/>
</div>
</xsl:template>
<xsl:template match="/dsQueryResponse/Rows/Row">
<div class="policy-item">
<div class="policy-item-title">
<xsl:value-of select="@Title" />
</div>
<xsl:if test="@ItemHtml != ''">
<div class="policy-item-content">
<xsl:value-of select="@ItemHtml" disable-output-escaping="yes" />
</div>
</xsl:if>
</div>
</xsl:template>
</xsl:stylesheet>
這絕對是你的XML看起來的樣子嗎?我在http://xsltransform.net/jyH9rMz上試過了你的XSLT,輸出對我來說確實很好。如果您是新手,那麼您絕對不會錯過XSLT的開始! – 2015-04-01 12:11:55
一類有錯誤的上下文,但除此之外,我認爲這種方法很好,請參閱http://xsltransform.net/gWmuiJx/1。您將需要使用真正的XSLT('>'永遠不會工作)和真正的XML編輯您的問題,在您的示例輸入 –
2015-04-01 12:12:21
中看不到英文'Category:Category 2 Title:Policy2'謝謝 - 我已經糾正了代碼,對不起,XML是錯誤的。因此,如果XSLT和XML都正確並且在xsltransform.net上工作,那麼我只能假設SharePoint沒有正確處理轉換?我正在使用DataView Web部件並將XSLT應用於此。 Tim,之前我做過很多XSLT,但是我從來沒有機會真正學過它,所以有很多反覆試驗和錯誤的習慣,可能還有壞習慣! – Dave 2015-04-01 12:25:41