{"id":2286,"date":"2017-03-31T14:21:19","date_gmt":"2017-03-31T12:21:19","guid":{"rendered":"http:\/\/www.itidea.nl\/?p=2286"},"modified":"2017-04-02T15:02:56","modified_gmt":"2017-04-02T13:02:56","slug":"xsltlistviewwebpart-property-xmldefinition-does-work","status":"publish","type":"post","link":"https:\/\/www.itidea.nl\/index.php\/xsltlistviewwebpart-property-xmldefinition-does-work\/","title":{"rendered":"XSLTListViewWebpart property XMLDefinition does work"},"content":{"rendered":"<p>Adding a list as web part to a page results in an XSLTListViewWebpart.<\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/1-XSLTListViewWebpart-initial-view.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-2295\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/1-XSLTListViewWebpart-initial-view-300x155.png\" alt=\"1-xsltlistviewwebpart-initial-view\" width=\"300\" height=\"155\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/1-XSLTListViewWebpart-initial-view-300x155.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/1-XSLTListViewWebpart-initial-view-768x397.png 768w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/1-XSLTListViewWebpart-initial-view-600x310.png 600w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/1-XSLTListViewWebpart-initial-view.png 857w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><em>Figure 1 Added a list to a page<\/em><\/p>\n<p>This results in a hidden view configured with the query and field references used. The accompanying view xml is shown in figure 3. Figure 2 displays the number of views before adding the web part to the page.<\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/2-XSLTListViewWebpart-initial-listviews.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2294\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/2-XSLTListViewWebpart-initial-listviews.png\" alt=\"2-xsltlistviewwebpart-initial-listviews\" width=\"173\" height=\"94\" \/><\/a><\/p>\n<p><em>Figure 2 Listviews before adding the list to a page<\/em><\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/3-XSLTListViewWebpart-hidden-view-xml.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2293 size-large\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/3-XSLTListViewWebpart-hidden-view-xml-1024x104.png\" alt=\"3-xsltlistviewwebpart-hidden-view-xml\" width=\"598\" height=\"61\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/3-XSLTListViewWebpart-hidden-view-xml-1024x104.png 1024w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/3-XSLTListViewWebpart-hidden-view-xml-300x31.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/3-XSLTListViewWebpart-hidden-view-xml-768x78.png 768w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/3-XSLTListViewWebpart-hidden-view-xml-600x61.png 600w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/3-XSLTListViewWebpart-hidden-view-xml.png 1514w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/a><\/p>\n<p><em>Figure 3 Hidden view configuration<\/em><\/p>\n<p>Configuring the fields shown in the web part results in a replaced hidden view.<br \/>\nThe view configured:<\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/4-XSLTListViewWebpart-configured-view.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-2292\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/4-XSLTListViewWebpart-configured-view-300x196.png\" alt=\"4-xsltlistviewwebpart-configured-view\" width=\"300\" height=\"196\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/4-XSLTListViewWebpart-configured-view-300x196.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/4-XSLTListViewWebpart-configured-view.png 422w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><em>Figure 4 Configured view<\/em><\/p>\n<p>And the accompanying xml shown in Figure 5.<\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/5-XSLTListViewWebpart-hidden-view-xml-new.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2296 size-large\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/5-XSLTListViewWebpart-hidden-view-xml-new-1024x77.png\" alt=\"5-xsltlistviewwebpart-hidden-view-xml-new\" width=\"598\" height=\"45\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/5-XSLTListViewWebpart-hidden-view-xml-new-1024x77.png 1024w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/5-XSLTListViewWebpart-hidden-view-xml-new-300x23.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/5-XSLTListViewWebpart-hidden-view-xml-new-768x58.png 768w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/5-XSLTListViewWebpart-hidden-view-xml-new-600x45.png 600w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/5-XSLTListViewWebpart-hidden-view-xml-new.png 1556w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/a><\/p>\n<p><em>Figure 5 Hidden view xml<\/em><\/p>\n<p>When this web part is exported to a web part file the view configuration is stored in an xml property called XmlDefinition.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;property name=&quot;XmlDefinition&quot; type=&quot;string&quot;&gt;\r\n&amp;lt;View Name=&quot;{4A2EFF1A-3B9D-4666-BED2-746669E3F037}&quot; MobileView=&quot;TRUE&quot; Type=&quot;HTML&quot;\r\nHidden=&quot;TRUE&quot; DisplayName=&quot;&quot; Url=&quot;\/teams\/testteamsite\/TestDefaultValue\/SitePages\/Home.aspx&quot;\r\nLevel=&quot;1&quot; BaseViewID=&quot;1&quot; ContentTypeID=&quot;0x&quot; ImageUrl=&quot;\/_layouts\/15\/images\/dlicon.png?rev=44&quot; &amp;gt;&amp;lt;\r\nQuery&amp;gt;&amp;lt;OrderBy&amp;gt;&amp;lt;FieldRef Name=&quot;FileLeafRef&quot;\/&amp;gt;&amp;lt;\/OrderBy&amp;gt;&amp;lt;\/Query&amp;gt;&amp;lt;\r\nViewFields&amp;gt;&amp;lt;FieldRef Name=&quot;DocIcon&quot;\/&amp;gt;&amp;lt;FieldRef Name=&quot;LinkFilename&quot;\/&amp;gt;&amp;lt;\r\nFieldRef Name=&quot;Modified&quot;\/&amp;gt;&amp;lt;FieldRef Name=&quot;_UIVersionString&quot;\/&amp;gt;&amp;lt;\/\r\nViewFields&amp;gt;&amp;lt;RowLimit Paged=&quot;TRUE&quot;&amp;gt;30&amp;lt;\/RowLimit&amp;gt;&amp;lt;Aggregations Value=&quot;Off&quot;\/&amp;gt;&amp;lt;\r\nJSLink&amp;gt;clienttemplates.js&amp;lt;\/JSLink&amp;gt;&amp;lt;XslLink Default=&quot;TRUE&quot;&amp;gt;main.xsl&amp;lt;\/XslLink&amp;gt;&amp;lt;\r\nToolbar Type=&quot;Standard&quot;\/&amp;gt;&amp;lt;\/View&amp;gt;\r\n&lt;\/property&gt;\r\n<\/pre>\n<p>Importing this web part through the UI or using SharePoint PnP (which uses CSOM in their modules) in the same web on another page results in a fully configured web part as exported and as expected, shown in figure 4.<br \/>\nSharePoint PnP is used here because the provisioning of pages has to be done most of the time in projects in a repeatable way.<\/p>\n<h4>Use in other web<\/h4>\n<p>Specific list references have to be removed (ListId property) or changed (ListUrl and ListName properties) when importing this web part in another web.<br \/>\nAfter modifying the properties of the web part file and import it on another web where the list specified in the xml exists, results in a default view as in Figure 1 using SharePoint PnP.<\/p>\n<p>The XmlDefinition property seems to be ignored, because the Version column isn&#8217;t visible.<\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/6-XSLTListViewWebpart-XmlDefinition-seems-to-be-ignored.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-2291\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/6-XSLTListViewWebpart-XmlDefinition-seems-to-be-ignored-300x188.png\" alt=\"6-xsltlistviewwebpart-xmldefinition-seems-to-be-ignored\" width=\"300\" height=\"188\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/6-XSLTListViewWebpart-XmlDefinition-seems-to-be-ignored-300x188.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/6-XSLTListViewWebpart-XmlDefinition-seems-to-be-ignored.png 428w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><em>Figure 6 XmlDefinition seens to be ignored, Version column not visible<\/em><\/p>\n<p>It seems to be ignored, because the exported data in the property isn&#8217;t valid.<\/p>\n<p>When there&#8217;s xml in a CDATA tag like shown in the xml snippet below, the configuration will be applied.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\r\n&lt;webParts&gt;\r\n&lt;webPart xmlns=&quot;&lt;a href=&quot;http:\/\/schemas.microsoft.com\/WebPart\/v3&quot;&gt;http:\/\/schemas.microsoft.com\/WebPart\/v3&lt;\/a&gt;&quot;&gt;\r\n&lt;metaData&gt;\r\n&lt;type name=&quot;Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=15.0.0.0,\r\n  Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; \/&gt;\r\n&lt;importErrorMessage&gt;Cannot import this Web Part.&lt;\/importErrorMessage&gt;\r\n&lt;\/metaData&gt;\r\n&lt;data&gt;\r\n&lt;properties&gt;\r\n&lt;property name=&quot;Title&quot; type=&quot;string&quot;&gt;Test&lt;\/property&gt;\r\n&lt;property name=&quot;ListName&quot; type=&quot;string&quot;&gt;DemoDocs&lt;\/property&gt;\r\n&lt;property name=&quot;ListUrl&quot; type=&quot;string&quot;&gt;DemoDocs&lt;\/property&gt;\r\n&lt;property name=&quot;XmlDefinition&quot; type=&quot;string&quot;&gt;&lt;!&#x5B;CDATA&#x5B;\r\n&lt;View Type=&quot;HTML&quot; Name=&quot;DoesntMatter&quot; BaseViewID=&quot;1&quot;&gt;\r\n&lt;Query&gt;\r\n&lt;GroupBy Collapse=&quot;TRUE&quot; GroupLimit=&quot;30&quot;&gt;\r\n&lt;FieldRef Name=&quot;Author&quot;\/&gt;\r\n&lt;\/GroupBy&gt;\r\n&lt;OrderBy&gt;\r\n&lt;FieldRef Name=&quot;Created&quot; Ascending=&quot;FALSE&quot;\/&gt;\r\n&lt;FieldRef Name=&quot;Title&quot;\/&gt;\r\n&lt;\/OrderBy&gt;\r\n&lt;\/Query&gt;\r\n&lt;ViewFields&gt;\r\n&lt;FieldRef Name=&quot;ID&quot;\/&gt;\r\n&lt;FieldRef Name=&quot;DocIcon&quot;\/&gt;\r\n&lt;FieldRef Name=&quot;LinkFilename&quot;\/&gt;\r\n&lt;FieldRef Name=&quot;Editor&quot;\/&gt;\r\n&lt;FieldRef Name=&quot;Created&quot;\/&gt;\r\n&lt;FieldRef Name=&quot;FileSizeDisplay&quot;\/&gt;\r\n&lt;\/ViewFields&gt;\r\n&lt;RowLimit Paged=&quot;TRUE&quot;&gt;9&lt;\/RowLimit&gt;\r\n&lt;Aggregations Value=&quot;On&quot;&gt;\r\n&lt;FieldRef Name=&quot;DocIcon&quot; Type=&quot;COUNT&quot;\/&gt;\r\n&lt;\/Aggregations&gt;\r\n&lt;JSLink&gt;clienttemplates.js&lt;\/JSLink&gt;\r\n&lt;Toolbar Type=&quot;Standard&quot;\/&gt;\r\n&lt;\/View&gt;]]&gt;&lt;\/property&gt;\r\n&lt;\/properties&gt;\r\n&lt;\/data&gt;\r\n&lt;\/webPart&gt;\r\n&lt;\/webParts&gt;\r\n<\/pre>\n<p>The result at the page:<\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/7-XSLTListViewWebpart-Configured-view-at-other-site.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2290 size-full\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/7-XSLTListViewWebpart-Configured-view-at-other-site.png\" alt=\"7-xsltlistviewwebpart-configured-view-at-other-site\" width=\"645\" height=\"364\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/7-XSLTListViewWebpart-Configured-view-at-other-site.png 645w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/7-XSLTListViewWebpart-Configured-view-at-other-site-300x169.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/7-XSLTListViewWebpart-Configured-view-at-other-site-600x339.png 600w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/a><\/p>\n<p><em>Figure 7 Configured view at other site<\/em><\/p>\n<p>Even the Toolbar set to None works:<\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/8-XSLTListViewWebpart-Configured-view-at-other-site-even-Toolbar-None-works.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2289\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/8-XSLTListViewWebpart-Configured-view-at-other-site-even-Toolbar-None-works.png\" alt=\"8-xsltlistviewwebpart-configured-view-at-other-site-even-toolbar-none-works\" width=\"662\" height=\"306\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/8-XSLTListViewWebpart-Configured-view-at-other-site-even-Toolbar-None-works.png 662w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/8-XSLTListViewWebpart-Configured-view-at-other-site-even-Toolbar-None-works-300x139.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/8-XSLTListViewWebpart-Configured-view-at-other-site-even-Toolbar-None-works-600x277.png 600w\" sizes=\"auto, (max-width: 662px) 100vw, 662px\" \/><\/a><\/p>\n<p><em>Figure 8: Toolbar None works as expected<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/9-XSLTListViewWebpart-view-xml-at-other-site-even-Toolbar-None-works.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2288 \" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/9-XSLTListViewWebpart-view-xml-at-other-site-even-Toolbar-None-works-1024x118.png\" alt=\"9-xsltlistviewwebpart-view-xml-at-other-site-even-toolbar-none-works\" width=\"650\" height=\"75\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/9-XSLTListViewWebpart-view-xml-at-other-site-even-Toolbar-None-works-1024x118.png 1024w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/9-XSLTListViewWebpart-view-xml-at-other-site-even-Toolbar-None-works-300x35.png 300w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/9-XSLTListViewWebpart-view-xml-at-other-site-even-Toolbar-None-works-768x89.png 768w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/9-XSLTListViewWebpart-view-xml-at-other-site-even-Toolbar-None-works-600x69.png 600w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2017\/04\/9-XSLTListViewWebpart-view-xml-at-other-site-even-Toolbar-None-works.png 1410w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/a><\/p>\n<p><em>Figure 9 Configured view xml<\/em><\/p>\n<h4>Summary<\/h4>\n<p><span lang=\"nl\">When an <\/span><span lang=\"en-US\">XSLTListViewWebpart is exported the<\/span><span lang=\"nl\"> XmlDefinition property contains xml which can&#8217;t be used when the webpart is imported in another site using client side object model. Use the CDATA tag as shown en it all works.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adding a list as web part to a page results in an XSLTListViewWebpart. Figure 1 Added a list to a page This results in a hidden view configured with the query and field references used. The accompanying view xml is &#8230; <a class=\"more-link\" href=\"https:\/\/www.itidea.nl\/index.php\/xsltlistviewwebpart-property-xmldefinition-does-work\/\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39,35],"tags":[37,44],"class_list":["post-2286","post","type-post","status-publish","format-standard","hentry","category-office-365","category-sharepoint-2013","tag-office365","tag-sharepoint-2013"],"_links":{"self":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/2286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/comments?post=2286"}],"version-history":[{"count":42,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/2286\/revisions"}],"predecessor-version":[{"id":2339,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/2286\/revisions\/2339"}],"wp:attachment":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/media?parent=2286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/categories?post=2286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/tags?post=2286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}