0

I am trying to style some results returned from the search webservice in 2010 with this stylesheet:

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
    <span>Matched root node</span>
    <div id="pSearchWrapper">
        <span>div pSearchWrapper</span>
        <xsl:call-template name="searchResults" />
    </div>
</xsl:template>
<xsl:template name="searchResults">
    <span>search Results Template</span>
    <xsl:for-each select="ResponsePacket/Response/Range/Results/Document" >
        <div class="individualResult">
            <xsl:call-template name="resultCard" />
        </div>
    </xsl:for-each>
</xsl:template>
<xsl:template name="resultCard">
    <xsl:variable name="pictureUrl" select="Properties/Property[starts-with(Name,'PICTUREURL')]/Value" />

    <div class="peoplePic" >
        <img>
            <xsl:attribute name="src">
                <xsl:value-of select="$pictureUrl" />
            </xsl:attribute>
        </img>
    </div>
</xsl:template>

Here is a snippet of the xml I am trying to style:

<ResponsePacket xmlns="urn:Microsoft.Search.Response">
<Response>
    <Range>
        <StartAt>1</StartAt>
        <Count>9</Count>
        <TotalAvailable>9</TotalAvailable>
        <Results>
            <Document xmlns="urn:Microsoft.Search.Response.Document">
                <Action>
                    <LinkUrl fileExt="aspx">http://mysites.domain.com/Person.aspx?accountname=blahblah</LinkUrl>
                </Action>
                <Properties xmlns="urn:Microsoft.Search.Response.Document.Document">
                    <Property>
                        <Name>TITLE</Name>
                        <Type>String</Type>
                        <Value>User</Value>
                    </Property>
                    <Property>
                        <Name>PATH</Name>
                        <Type>String</Type>
                        <Value>http://mysites.domain.com/Person.aspx?accountname=blahblahR</Value>
                    </Property>
                    <Property>
                        <Name>WRITE</Name>
                        <Type>DateTime</Type>
                        <Value>2013-05-07T06:59:07</Value>
                    </Property>
                    <Property>
                        <Name>RANK</Name>
                        <Type>Int64</Type>
                        <Value>0</Value>
                    </Property>
                    <Property>
                        <Name>SIZE</Name>
                        <Type>Int64</Type>
                        <Value>0</Value>
                    </Property>
                    <Property>
                        <Name>PICTUREURL</Name>
                        <Type>String</Type>
                        <Value>http://mysites.domain.com/User Photos/Profile Pictures/blahblah.jpg</Value>
                    </Property>
                    <Property>
                        <Name>PREFERREDNAME</Name>
                        <Type>String</Type>
                        <Value>User</Value>
                    </Property>
                    <Property>
                        <Name>WORKPHONE</Name>
                        <Type>String</Type>
                        <Value>69342</Value>
                    </Property>
                    <Property>
                        <Name>WORKEMAIL</Name>
                        <Type>String</Type>
                        <Value>[email protected]</Value>
                    </Property>
                </Properties>
            </Document>
        </Results>
    </Range>
    <Status>SUCCESS</Status>
</Response>

The stylesheet renders up until the for-each loop. I tried this with an apply-templates call and it failed at basically the same point. This leads me to believe that there is something wrong in the path specified in the select attribute. Any help would be greatly appreciated.

BTW: I am transfoming the xml through a javascript call.

2 Answers 2

0

in this post you can find how to debug your xslt code: http://salvatoredifaziosharepoint.blogspot.co.uk/2012/04/how-to-modify-sharepoints-result-page.html

Basically I can't help you on-the-fly you have to debug your code.

0

Salvatore, thanks for your suggestion, but Visual Studio didn't tell me anymore than I had known in the two days I had spent trying to debug the code before posting the question. I had a coworker take a look and he noticed that it would work without the namespace declarations in the xml. Since the xml is from the search web service, I can't remove the namespaces. I did, however, figure out how to reference them in my stylesheet. Here is the working code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rp ="urn:Microsoft.Search.Response" xmlns:doc="urn:Microsoft.Search.Response.Document" xmlns:prop="urn:Microsoft.Search.Response.Document.Document">
  <xsl:output method="html"/>
  <xsl:template match="/">
    <div id="pSearchWrapper">
      <xsl:call-template name="searchResults" />
    </div>
  </xsl:template>
  <xsl:template name="searchResults">
    <xsl:for-each select="/rp:ResponsePacket/rp:Response/rp:Range/rp:Results/doc:Document" >
      <div class="individualResult" style="clear:both">
        <xsl:call-template name="resultCard" />
      </div>
    </xsl:for-each>
  </xsl:template>
  <xsl:template name="resultCard">
    <xsl:variable name="pictureUrl" select="prop:Properties/prop:Property[prop:Name='PICTUREURL']/prop:Value" />

    <div class="peoplePic" style="display:inline-block;width:100px" >
      <img>
        <xsl:attribute name="src">
          <xsl:value-of select="$pictureUrl" />
        </xsl:attribute>
      </img>
    </div>
    <div style="display:inline-block">
        <div class = "cpName">
            <xsl:value-of select="prop:Properties/prop:Property[prop:Name='PREFERREDNAME']/prop:Value" />
        </div>
        <div class="workPhone">
            <xsl:text>Ext: </xsl:text>
            <xsl:value-of select="prop:Properties/prop:Property[prop:Name='WORKPHONE']/prop:Value" />
        </div>
        <div class="email">
            <xsl:value-of select="prop:Properties/prop:Property[prop:Name='WORKEMAIL']/prop:Value" />
        </div>
    </div>
  </xsl:template>
</xsl:stylesheet>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.