Correct xsl links for web part in page layout (after deployment)
#file is already downloaded in c:\temp
#input parameters
$siteUrl="https://localhost/sites/events"
$srcPath="c:\temp"
$fileName="NewsLayoutDetails.aspx" #"chamEventPageLayout.aspx"
function GetSiteFromUrl(
[string]$url
)
{
$first=$url.IndexOf('/')
$short=$url.substring($first+2,$url.length-$first-2)
$index=$short.IndexOf('/')
$site=$short.substring($index+1, $short.length-$index-1)
return $site
}
$file=(get-content ($srcPath+"\"+$fileName))
#Get all properties with XslLink text (not error if node doesn't exist)
#this is in layout.aspx file
#MainXslLink="/sites/events/Style Library/Banner/PagingButtons.xslt"
#we want to cut link first: /Style Library/Banner/PagingButtons.xslt"
#then add current site collection url: /sites/othersite/Style Library/Banner/PagingButtons.xslt"
$prefix=GetSiteFromUrl -url $siteUrl
$prefix="/"+ $prefix
#$prefix
function InsertPrefixToUrl
{
param([object]$link, [string]$prefix, [string]$item)
#find '/Style libray' text position in link
$lstring=$link.ToString()
write-host "Old link: "$lstring
$length=$lstring.length
$position=([regex]::match($lstring,"/Style Library")).Index
$cutLink=$lstring.substring($position, $length-$position)
$newLink=[string]::Format('{2}="{0}{1}',$prefix, $cutLink, $item)
write-host "New link: " $newLink
return $newLink
}
$links=@("MainXslLink", "HeaderXslLink", "ItemXslLink")
#$file -replace "Main", "Header" |set-content ($srcPath+"\"+$fileName)
foreach($item in $links)
{
$xslLinks=$file|select-string $item #get all links of category
if($xslLinks -ne $null)
{
foreach($link in $xslLinks)
{
$file=(get-content ($srcPath+"\"+$fileName))
$file -replace $link.ToString(),(InsertPrefixToUrl -link $link -prefix $prefix -item $item)|set-content ($srcPath+"\"+$fileName)
}
}
}