Flokkaskjalasafn: SharePoint Þróun

Varast Breaking Breytingar á ItemStyle.xsl

Ég var að vinna með ItemStyle.xsl að sérsníða útlit af a Fyrirspurn Content Web Part og rétt um hádegi, I made a breaking change to the xsl. I didn’t realize it, but this had far reaching effects throughout the site collection. I went off to lunch and upon my return, tekið þessi skilaboð birtast í fullt af stöðum:

Ekki tókst að birta þetta Web Part. Til að leysa vandann, opna þessa vefsíðu í Windows SharePoint Services-samhæft HTML ritil eins og Microsoft Office SharePoint Designer. Ef vandamálið er viðvarandi, samband vefþjóninn kerfisstjóra.

Ég kennt viðskiptavinur (ekki átta sig eins og enn, að það var mér að kenna á þessum tímapunkti) but eventually noticed that visual studio intellisense was warning me that I had malformed XSL. I corrected it and everything started working.

Verið darned varkár þegar að vinna með ItemStyle.xsl (og eitthvað af alþjóðlegum XSL skrá) — brjóta þá snertir marga artifacts í the staður safn.

<endir />

Sýna efni Fyrirspurn Web Part uppgjör í töflu / Tafla

Yfirlit og Markmið

Út af the kassi, Moss’ Efni Fyrirspurn Web Part (CQWP) birtir uppgjör sitt á lista sniði, similar to search results. It is also possible to display the results in a grid format (i.e. HTML töflu snið). Grid formats are better in some circumstances. I describe how to achieve that effect in this article.

Viðskipti Atburðarás

I have worked with a client on an enterprise-wide MOSS rollout. We have designed their taxonomy such that projects are first class citizens in the hierarchy and have their own top level site. Project managers maintain a singleton list of project summary information, svo sem titil, fjárhagsáætlun, ráð verklok, remaining budget and other summary type fields. By "singleton" I mean a custom SharePoint list guaranteed to contain only one item. Simplistically, það lítur svona út:

mynd

Tæknilega nálgun er mikill the sami eins og lýst hér (http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!447.entry). The CQWP uses an XSL transform to emit HTML for the browser to render.

I always envision the result before diving into the XSL because XSL is a nightmare. Here’s my desired result:

mynd

HTML svona býr að niðurstöðu:

<HTML>
 <líkami>
 <miðstöð>
 <borð landamæri= 1>

<!-- Merki ->
 <tr bgcolor= Blár>
 <td><letur litur= Hvítt><B>Project Name</B></letur></td>
 <td align= Rétt><letur litur= Hvítt><B>Ljúka Dagsetning</B></letur></td>
 <td align= Rétt><letur litur= Hvítt><B>Budget</B></letur></td>
 <td align= Rétt><letur litur= Hvítt><B>Raunveruleg kostnað</B></letur></td>
 <td><letur litur= Hvítt><B>Alls Status</B></letur></td>
 </tr>

<tr>
 <td>Re-vír tölvu herbergi.</td>
 <td align= Rétt>02/01/08</td>
 <td align= Rétt>22,500.00</td>
 <td align= Rétt>19,000.00</td>
 <td>Í vinnslu</td>
 </tr>

<tr>
 <td>Framlag netþjóna fyrir SQL Uppfærsla</td>
 <td align= Rétt>04/01/08</td>
 <td align= Rétt>7,500.00</td>
 <td align= Rétt>0.00</td>
 <td>Planned</td>
 </tr>

</borð>
 </miðstöð>
 </líkami>
</HTML>

Nálgun

Fylgdu þessum skrefum til að búa rist:

  1. Þekkja þá hluti af rist (raðir / dálka).
  2. Skilgreina og skapa nauðsynlegar dálka síða.
  3. Búa undir síður fyrir verkefni og Singleton lista.
  4. Bæta við CQWP á vefsíðu og stilla það til að leita að listum.
  5. Breyta XML í CQWP að safna upp frekari dálka.
  6. Breyta XSL til að búa til töflu.

I’m going to concentrate on number six. Numbers one through four are straight-forward and something that any CQWP user has already done. Number five has been well-documented by others including this exhaustive screen-shot laden article from MSDN hér (http://msdn2.microsoft.com/en-us/library/bb897399.aspx) og bloggið Heather Salómons hér (http://www.heathersolomon.com/blog/articles/CustomItemStyle.aspx).

Hnetur og boltar

Byrja og framkvæma skref eitt til fimm eins og á MSDN skjöl og greinar Heather Salómons.

Á þessum tímapunkti, þú bættir CQWP til síðu og þú hafa þinn <CommonViewFields> stillt eftir þörfum.

Eftir venjulega skrefum, Ég fæ þessar millistig niðurstöður:

1. Búa gerð efnis, a templatized custom list for that content type and two sites. Here is the content type:

mynd

Hér er síða uppbygging:

mynd

2. Bæta við CQWP eftir að búa verkefni undirvefsvæðum mínar og Singleton verkefnisins samantekt listi:

mynd

3. Bæta allar frekari upplýsingar sem ég vil í gegnum <CommonViewFields>:

        <eign nafn="CommonViewFields" tegund="band">Project_x0020_Name;Project_x0020_Expenses;Project_x0020_Status;Project_x0020_Start_x0020_Date;Project_x0020_End_x0020_Date;Project_x0020_Budget</eign>

Athugaðu að ég þurfti að halda öllum eignum reiti í einni línu eða það myndi ekki virka (CQWP myndi segja mér að fyrirspurn skilað engar vörur).

4. Á þessum tímapunkti, we’re ready to move beyond the MSDN article and flip on over to Heather Solomon’s article. Follow her steps starting near step #5 til að búa til sérsniðna / unghosted version of ItemStyle.xsl. I follow Heather’s advice, upp í gegnum skref 11 og fá þessir millistig niðurstöður:

4.1: Nafn XSL sniðmát mitt eftirfarandi:

<XSL:template name="Grid" match="Row[@Style=’Grid’]" mode="itemstyle">

Ég líka örlítið breytt henni leiðbeinandi <XSL:fyrir-hvern …> með því að bæta <br /> merkja að veita hreinni skráningu:

    <XSL:fyrir-hvern velja="@ *">
      P:<XSL:gildi-af velja="nafn()" /><br/>
    </XSL:fyrir-hvern>

4.2: Ég breyta vefur hluti, go to appearance and select my "Grid" stíl:

mynd

Sækja breytinguna og hér er útkoman:

mynd

Við sjáum af ofangreindu að reitir við viljum (Verkefnið nafn, kostnað, staða, o.fl.) are available for us to use when we emit the HTML. Not only that, but we see the names by which we must reference those columns in the XSL. Til dæmis, we reference Project Status as "Project_x005F_x0020_Name".

Á þessum tímapunkti, við víkja úr blogginu lyngi og frá herðum þessara risa, Ég bæta við eigin svolítið minn.

ContentQueryMain.xsl

ATHUGIÐ: Þegar að gera breytingar á bæði ContentQueryMain.xsl auk ItemStyle.xsl, þú þarft að athuga þær skrár aftur í áður en þú sjá áhrif af breytingum þínum.

Fyrir rist-gerð tilgangi, MOSS uses two different XSL files to produce the results we see from a CQWP. To generate the previous bit of output, we modified ItemStyle.xsl. MOSS actually uses another XSL file, ContentQueryMain.xsl to in conjunction with ItemStyle.xsl to generate its HTML. As its name implies, ContentQueryMain.xsl is the "main" XSL that controls the overall flow of translation. It iterates through all the found items and passes them one by one to templates in ItemStyle.xsl. We’ll modify ItemStyle.xsl to generate the open <borð> skipun á undan emitting fyrstu röðinni af gögnum og lokun <borð> tag after emitting the last row. To accomplish this, ContentQueryMain.xsl is modified to pass two parameters to our "grid" sniðmát í ItemStyle.xsl, "last row" and "current row". ItemStyle.xsl uses these to conditionally emit the necessary tags.

Notkun tækni Heather Salómons, we locate ContentQueryMain.xsl. It is located in the same place as ItemStyle.xsl. This screen shot should help:

mynd

Við þurfum að gera eftirfarandi breytingar:

  • Breyta í XSL sniðmát, "CallItemTemplate" that actually invokes our Grid template in ItemStyle.xsl. We will pass two parameters to the Grid template so that it will have the data it needs to conditionally generate opening and closing <borð> merki.
  • Modify another bit of ContentQueryMain.xsl that calls the "CallItemTemplate" to pass it a "LastRow" breytu þannig að LastRow má um að Grid sniðmát okkar.

Locate the template named "OuterTemplate.CallItemTemplate" auðkennd með streng:

  <XSL:sniðmát nafn="OuterTemplate.CallItemTemplate">

Settu alla sniðmát sem fylgir:

  <XSL:sniðmát nafn="OuterTemplate.CallItemTemplate">
    <XSL:Gildi nafn="CurPosition" />

    <!--
      Add the "LastRow" breytu.
      We only use it when the item style pass in is "Grid".
    -->
    <XSL:Gildi nafn="LastRow" />

    <XSL:velja>
      <XSL:þegar próf="@ Style = 'NewsRollUpItem'">
        <XSL:gilda-sniðmát velja="." ham="itemstyle">
          <XSL:með-Gildi nafn="EditMode" velja="$cbq_iseditmode" />
        </XSL:gilda-sniðmát>
      </XSL:þegar>
      <XSL:þegar próf="@ Style = 'NewsBigItem'">
        <XSL:gilda-sniðmát velja="." ham="itemstyle">
          <XSL:með-Gildi nafn="CurPos" velja="$CurPosition" />
        </XSL:gilda-sniðmát>
      </XSL:þegar>
      <XSL:þegar próf="@ Style = 'NewsCategoryItem'">
        <XSL:gilda-sniðmát velja="." ham="itemstyle">
          <XSL:með-Gildi nafn="CurPos" velja="$CurPosition" />
        </XSL:gilda-sniðmát>
      </XSL:þegar>

      <!--
              Pass núverandi stöðu og lastrow til itemstyle.xsl Grid sniðmát.
              ItemStyle.xsl mun nota það til að senda frá sér opna og loka <borð> merki.
      -->
      <XSL:þegar próf="@ Style = 'Tafla'">
        <XSL:gilda-sniðmát velja="." ham="itemstyle">
          <XSL:með-Gildi nafn="CurPos" velja="$CurPosition" />
          <XSL:með-Gildi nafn="Síðast" velja="$LastRow" />
        </XSL:gilda-sniðmát>
      </XSL:þegar>

      <XSL:annars>
        <XSL:gilda-sniðmát velja="." ham="itemstyle">
        </XSL:gilda-sniðmát>
      </XSL:annars>
    </XSL:velja>
  </XSL:sniðmát>

Athugasemdirnar lýsa tilgangi breytingar.

Auðvitað, the "OuterTemplate.CallItemTemplate" is itself called from another template. Locate that template by searching for this text string:

<XSL:sniðmát nafn="OuterTemplate.Body">

Fletta í gegnum leiðbeiningar á OuterTemplate.Body og settu LastRow breytu sem hér segir (sýndur sem athugasemd í skáletrun):

<XSL:kalla-sniðmát nafn="OuterTemplate.CallItemTemplate">
  <XSL:með-Gildi nafn="CurPosition" velja="$CurPosition" />
  <!-- Settu LastRow breytu. -->
  <XSL:með-Gildi nafn="LastRow" velja="$LastRow"/>
</XSL:kalla-sniðmát>

Eftir allt þetta, við loksins hefur það sett upp á réttan hátt þannig að ItemStyle.xsl okkar getur gefið frá sér <borð> Tags á réttum stað.

ItemStyle.Xsl

ATHUGIÐ: Aftur, athuga í ItemStyle.xsl eftir að gera neinar breytingar þannig að þú sjá áhrif af þessum breytingum.

Við höfum tvö verkefni hér:

  • Replace the entire Grid template. You can copy/paste from below.
  • Add some mumbo jumbo outside the template definition that enables "formatcurrency" template to work. (Þú getur sagt að ég hafi örlitla séð á XSL).

Fyrsta, ofarlega ItemStyle.xsl, bæta við þessa línu:

  <!-- Sumir muldra tröllvaxinn sem gerir okkur kleift að sýna bandarískt. mynt. -->
  <XSL:aukastaf-sniði nafn="starfsfólk" stafa="D" />

  <XSL:sniðmát nafn="Default" passa="*" ham="itemstyle">

Athugaðu að ég bætti það beint áður en <XSL:template name="Default" …> skýring.

Næsta, go back to our Grid template. Replace the entire Grid template with the code below. It is thoroughly commented, en ekki hika við að sendu mér tölvupóst eða leyfi athugasemdir á blogginu mínu ef þú hefur einhverjar spurningar.

  <XSL:sniðmát nafn="Rist" passa="Róður[@ Style = 'Tafla']" ham="itemstyle">

    <!--
      ContentMain.xsl fer CurPos og síðasta.
      Við notum þetta til skilyrðum losa opinn og loka <borð> merki.
    -->
    <XSL:Gildi nafn="CurPos" />
    <XSL:Gildi nafn="Síðast" />

    <!-- Eftirfarandi breytur eru óbreytt frá venjulegu ItemStyle.xsl -->
    <XSL:breytu nafn="SafeImageUrl">
      <XSL:kalla-sniðmát nafn="OuterTemplate.GetSafeStaticUrl">
        <XSL:með-Gildi nafn="UrlColumnName" velja="'ImageUrl'"/>
      </XSL:kalla-sniðmát>
    </XSL:breytu>
    <XSL:breytu nafn="SafeLinkUrl">
      <XSL:kalla-sniðmát nafn="OuterTemplate.GetSafeLink">
        <XSL:með-Gildi nafn="UrlColumnName" velja="'LinkUrl'"/>
      </XSL:kalla-sniðmát>
    </XSL:breytu>
    <XSL:breytu nafn="DisplayTitle">
      <XSL:kalla-sniðmát nafn="OuterTemplate.GetTitle">
        <XSL:með-Gildi nafn="Titill" velja="@ Titill"/>
        <XSL:með-Gildi nafn="UrlColumnName" velja="'LinkUrl'"/>
      </XSL:kalla-sniðmát>
    </XSL:breytu>
    <XSL:breytu nafn="LinkTarget">
      <XSL:ef próf="@ OpenInNewWindow = 'true'" >_blank</XSL:ef>
    </XSL:breytu>

    <!--
      Hér við skilgreinum breytu, "tableStart".  Þetta inniheldur HTML
      .  Athugið að ef CurPos = 1, það felur í sér HTML í cdata tag.
      Annars, það mun vera tómur.

      Verðmæti tableStart er emited hvert skipti ItemStyle er kallað í gegnum
      .
    -->
    <XSL:breytu nafn="tableStart">
      <XSL:ef próf="$CurPos = 1">
        <![CDATA[
        <Tafla border = 1>
          <tr bgcolor="blue">
            <td><font color="white"><B>Project Name</B></letur></td>
            <td align="right"><font color="white"><B>Ljúka Dagsetning</B></letur></td>
            <td align="right"><font color="white"><B>Budget</B></letur></td>
            <td align="right"><font color="white"><B>Raunveruleg kostnað</B></letur></td>
            <td><font color="white"><B>Alls Status</B></letur></td>
          </tr>
        ]]>
      </XSL:ef>
    </XSL:breytu>

    <!--
      Annar breytu, tableEnd skilgreinir einfaldlega borðið lokun tag.

      Eins og með tableStart, það er alltaf emited.  Þetta er ástæða þess að gildi þess er
      .
    -->
    <XSL:breytu nafn="tableEnd">
      <XSL:ef próf="$CurPos = $ Síðast">
        <![CDATA[ </borð> ]]>
      </XSL:ef>
    </XSL:breytu>

    <!--
      Alltaf losa innihald tableStart.  Ef þetta er ekki í fyrsta
      , þá vitum við gildi þess
      .

      Slökkva framleiðsla sleppi því þegar tableStart ekki autt, það
      .  Ef
      , it will generate
      stuff like "&lt;borð&GT;" instead of "<borð>".
    -->
    <XSL:gildi-af velja="$tableStart" disable-framleiðsla sleppi=""/>


    <tr>
      <!--
      P:Project_x005F_x0020_Name
      :Project_x005F_x0020_End_x005F_x0020_Date
      :Project_x005F_x0020_Budget
      :Project_x005F_x0020_Expenses
      :Project_x005F_x0020_Status
      -->
      <td>
        <XSL:gildi-af velja="@ Project_x005F_x0020_Name"/>
      </td>

      <td align="rétt">
        <XSL:gildi-af velja="@ Project_x005F_x0020_End_x005F_x0020_Date"/>
      </td>

      <td align="rétt">
        <XSL:kalla-sniðmát nafn="formatcurrency">
          <XSL:með-Gildi nafn="gildi" 
velja="@ Project_x005F_x0020_Budget"></XSL:með-Gildi> </XSL:kalla-sniðmát> </td> <td align="rétt"> <XSL:kalla-sniðmát nafn="formatcurrency"> <XSL:með-Gildi nafn="gildi" velja="@ Project_x005F_x0020_Expenses">
</XSL:með-Gildi> </XSL:kalla-sniðmát> </td> <td> <XSL:gildi-af velja="@ Project_x005F_x0020_Status"/> </td> <!-- Allar eftirfarandi er athugasemd út til að skýra hlutina. Hins, koma með það aftur og efni það inn í a <td> að sjá sína         . --> <!-- <div id="linkitem" class="item"> <XSL:if test="string-length($SafeImageUrl) != 0"> <div class="image-area-left"> <a href="{$SafeLinkUrl}" target="{$LinkTarget}"> <img class="image-fixed-width" src="{$SafeImageUrl}"
alt="{@ ImageUrlAltText}"/> </a> </div> </XSL:ef> <div class="link-item"> <XSL:kalla-sniðmát
name="OuterTemplate.CallPresenceStatusIconTemplate"/> <a href="{$SafeLinkUrl}"
target="{$LinkTarget}" title="{@ LinkToolTip}"> <XSL:value-of select="$DisplayTitle"/> </a> <div class="description"> <XSL:value-of select="@Description" /> </div> </div> </div>
--> </tr> <!-- Losa borðið lokun tag. Ef við erum ekki á síðustu röðinni, þetta mun vera autt. --> <XSL:gildi-af velja="$tableEnd" disable-framleiðsla sleppi=""/> </XSL:sniðmát> <XSL:sniðmát nafn="formatcurrency"> <XSL:Gildi nafn="gildi" velja="0" /> <XSL:gildi-af velja="snið-númer($gildi, "$DDD,DDD,DDD.DD", "staff")" /> </XSL:sniðmát>

Standard WSS / MOSS Gögn Entry Skjár styðja ekki Cascading falla-hæðir (eða annar innan frá samskiptum)

UPDATE (04/2008): Þessi mikli blogg sýnir góðan javascript byggir nálgun á þessu vandamáli: http://webborg.blogspot.com/2008/04/add-functions-and-events-to-sharepoint.html

UPDATE II: (04/2008): Þetta blogg útlit efnilegur og: http://www.cleverworkarounds.com/2008/03/13/free-mosswss-2007-web-part-hide-controls-via-javascript/

Nokkrum sinnum í viku, ef ekki daglega, forum users describe a requirement that would normally be met via cascading drop-downs. Til dæmis, Ég hef tvær falla niður eftirlit:

  • Listi yfir bandarískt. ríki
  • Listi yfir bandarískt. cities.

As responsible UI providers, we want it to operate like this:

  • Paul selects a U.S. state from the drop-down.
  • This causes the cities drop-down to filter only those cities that belong to the selected state.
  • Paul selects a city from this filtered list.

There is no out-of-the-box support for this feature. Í raun, there is no OOB support for any kind of direct intra-form communication. This includes programmatically hiding/enabling/disabling fields in response to field changes elsewhere on the form.

The real objective of this article to to describe possible solutions and these are the options as I know them:

  1. Develop a custom column type. As a custom-column-developer, you have full control over the "world" of that custom column. You can implement a cascading drop-down that way.
  2. Consider using workflow. In some cases, you want to automatically assign a value to field based on another field’s value. Í þessu tilviki, you would normally try to use a calculated column, but some times, it just won’t get the job done. SharePoint Designer workflow is a relatively administer-friendly alternative to dropping down into code and visual studio. If you go this route, be aware of the issue addressed by þessi grein (http://paulgalvin.spaces.live.com/blog/cns!CC1EDB3DAA9B8AA!405.entry).
  3. Event handlers: Like workflow, this is an after-the-fact solution. Your event handler is a .NET assembly (C #, VB.NET) to which SharePoint passes control. The object you develop has access to the data of the list (and the whole object model) and can do any needed calculation.
  4. Use SharePoint Designer to create custom entry forms. I don’t have direct experience with this approach, but I hear they are doing good things with NewForm.aspx these days 🙂
  5. Roll your own ASP.NET data entry function (as a stand-alone web page or as a web part) and use that instead.

If anyone knows other and/or better options, please post a comment and I’ll update the body of this post.

<endir />

Technorati Tags:

Búa til Bar myndrit í SharePoint

Yfirlit:

(UPDATE 12/04/07: Við annað áhugavert auðlind í lok tengja við annað blog sem fjallar þetta um mjög áhugavert vefur hluti)

This blog entry describes how to create a bar graph in SharePoint. This works in both WSS and MOSS environments as it only depends upon the data view web part.

The overall approach is as follows:

  1. Create a list or document library that contains the data you want to graph.
  2. Place the associated document library / custom list onto a page and convert it to a data view web part (DVWP).
  3. Modify the DVWP’s XSL to generate HTML that shows as a graph.

Viðskipti Atburðarás / Setup:

I have created a custom list with the standard Title column and one additional column, "Status". This models (very simplistically) an "Authorization For Expense" scenario where the title represents the project and the Status a value from the list of:

  • Proposed
  • In Process
  • Stalled

The objective is to produce an interactive horizontal bar graph that shows these status codes.

I have populated the list and it looks like this:

mynd

Create Data View Web Part:

Create the DVWP by adding the custom list to a page (site page in my case) and follow the instructions hér (http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!395.entry).

In addition to simply creating the DVWP, we also need to set the paging property to show all available rows. Fyrir mig, this looks something like this:

mynd

Á þessum tímapunkti, I always close SPD and the browser. I then re-open the page using the browser. This avoids accidentally mucking up the web part layout on the page.

Modify the XSLT:

It’s now time to modify the XSLT.

I always use visual studio for this. (Sjá hér for an important note about intellisense that will help you a lot).

I create an empty project add four new files (replacing the words "Original" and "New" as appropriate):

  • Original.xslt
  • New.xslt
  • Original Params.xml
  • New Params.xml

Í mínu tilfelli, það lítur svona út:

mynd

Modify the web part and copy the params and XSL to the "Original" version in Visual Studio.

The objective here is to cause the XSL to transform the results we get back from the DVWP query into HTML that renders as a graph.

Í þessu skyni, it helps to first consider what the HTML should look like before we get confused by the insanity that is known as "XSL". (To be clear, the following is simply an example; don’t type it or copy/paste into visual studio. I provide a full blow starting point for that later in the write-up). The following sample graph is rendered as per the HTML immediately following:

Sample Bar Graph

Corresponding HTML:

<HTML>
<líkami>
<miðstöð>
<table width=80%>
<tr><td><miðstöð>Horizontal Bar Graph</td></tr>
<tr>
<td align="center">
<table border="1" width=80%>
<tr>
<td width=10%>Open</td>
<td><table cellpadding="0" cellspacing="0" border=0 width=50%><tr bgcolor=red><td>&nbsp;</td></tr></borð></td>
</tr>
<tr>
<td width=10%>Closed</td>
<td><table cellpadding="0" cellspacing="0" border=0 width=25%><tr bgcolor=red><td>&nbsp;</td></tr></borð></td>
</tr>
<tr>
<td width=10%>Stalled</td>
<td><table cellpadding="0" cellspacing="0" border=0 width=25%><tr bgcolor=red><td>&nbsp;</td></tr></borð></td>
</tr>
</borð>
</td>
</tr>
</borð>
</líkami>
</HTML>

I used a dead simple approach to creating my bars by setting the background color of a row to "red".

The take-away here is this: Í lok, all we are doing is creating HTML with rows and columns.

Template XSLT:

I’ve copied the XSLT that generates a horizontal bar graph. It’s fairly well commented so I won’t add much here except for these notes:

  • I started with the default XSL that SharePoint Designer gave me when I first created the DVWP.
  • I was able to cut this down from SPD’s 657 lines to 166 lines.
  • I didn’t mess around with the parameters XML file (which is separate from the XSL and you’ll know what I mean when you go to modify the DVWP itself; there are two files you can modify). Hins, in order to simplify it, I did remove nearly all of them from the XSL. This means that if you want to make use of those parameters, you just need to add their variable definitions back to the XSL. That will be easy since you will have the original XSL variable definitions in your visual studio project.
  • You ought to be able to copy and paste this directly into your visual studio project. Þá, remove my calls and insert your own calls to "ShowBar".
  • The drill down works by creating an <a href> like this: http://server/List?FilterField1=fieldname&FilterValue1=actualFilterValue. This technique may be of value in other contexts. Í fyrstu, I thought I would need to conform to a more complex format: http://server/List/AllItems.aspx?View={guid}&FilterField1=blah&FilterValue1=blah, but in my environment that is not necessary. The List’s URL is passed to us by SharePoint so this is quite easy to generalize.

Here it is:

<XSL:stílsíðu útgáfa="1.0" exclude-result-prefixes="rs z o s ddwrt dt msxsl" 
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 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:ASP="HTTP://schemas.microsoft.com/ASPNET/20" xmlns:ddwrt="HTTP://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:o="urn:schemas-microsoft-com:office" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"
xmlns:ddwrt2="urn:frontpage:internal"
> <XSL:framleiðsla aðferð="HTML" undirlið="no" /> <XSL:aukastaf-sniði NaN="" /> <XSL:Gildi nafn="ListUrlDir"></XSL:Gildi> <!-- I need this to support a drill-down. --> <XSL:sniðmát passa="/" xmlns:SharePoint="Microsoft.SharePoint.WebControls"
xmlns:__designer=http://schemas.microsoft.com/WebParts/v2/DataView/designer xmlns:ASP="HTTP://schemas.microsoft.com/ASPNET/20"
> <XSL:breytu nafn="dvt_StyleName">Tafla</XSL:breytu> <XSL:breytu nafn="Rows" velja="/dsQueryResponse/Rows/Row" /> <XSL:breytu nafn="dvt_RowCount" velja="count($Rows)" /> <XSL:breytu nafn="IsEmpty" velja="$dvt_RowCount = 0" /> <XSL:breytu nafn="dvt_IsEmpty" velja="$dvt_RowCount = 0" /> <XSL:velja> <XSL:þegar próf="$dvt_IsEmpty"> There is no data to graph!<br/> </XSL:þegar> <XSL:annars> <!-- The interesting stuff begins here. We need to define a pair of variables for each row in the graph: total number of items and percent of total. --> <XSL:breytu nafn="totalProposed" velja="count(/dsQueryResponse/Rows/Row[normalize-space(@Status) = 'Proposed'])" /> <XSL:breytu nafn="percentProposed" velja="$totalProposed div $dvt_RowCount" /> <XSL:breytu nafn="totalInProcess" velja="count(/dsQueryResponse/Rows/Row[normalize-space(@Status) = 'In Process'])" /> <XSL:breytu nafn="percentInProcess" velja="$totalInProcess div $dvt_RowCount" /> <XSL:breytu nafn="totalStalled" velja="count(/dsQueryResponse/Rows/Row[normalize-space(@Status) = 'Stalled'])" /> <XSL:breytu nafn="percentStalled" velja="$totalStalled div $dvt_RowCount" /> <!-- We define our HTML table here. I'm borrowing from some standard SharePoint styles here to make it consistent. I think it will honor changes to the global css file as well as theme overrides. --> <borð breidd="100%" cellspacing="0" cellpadding="2" stíl="border-right: 1 solid #C0C0C0; border-bottom: 1 solid #C0C0C0; border-left-style: solid; border-left-width: 1; border-top-style: solid; border-top-width: 1;"> <tr> <td align="miðstöð"> <borð landamæri="1" breidd="100%"> <!-- For each status that we want to graph, we call the "ShowBar" sniðmát. We pass it: 1. A label for the row. This is transformed into a hyperlink. 2. The percent (variable from above). 3. The actual field name of the code from the underlying list. This does not need to match the display label. 4. Field value matched for #3. 5. Total items of this status code (not the grand total of all status codes). It emits a <tr></tr> and the horizontal bar graph line. We call this template for each status code we want to view. --> <XSL:kalla-sniðmát nafn="ShowBar"> <XSL:með-Gildi nafn="BarDisplayLabel" velja="'Proposed'"/> <XSL:með-Gildi nafn="BarPercent" velja="$percentProposed"/> <XSL:með-Gildi nafn="QueryFilterFieldName" velja="'Status'"/> <XSL:með-Gildi nafn="QueryFilterFieldValue" velja="'Proposed'"/> <XSL:með-Gildi nafn="TotalItems" velja="$totalProposed"></XSL:með-Gildi> </XSL:kalla-sniðmát> <XSL:kalla-sniðmát nafn="ShowBar"> <XSL:með-Gildi nafn="BarDisplayLabel" velja="'Stalled'"/> <XSL:með-Gildi nafn="BarPercent" velja="$percentStalled"/> <XSL:með-Gildi nafn="QueryFilterFieldName" velja="'Status'"/> <XSL:með-Gildi nafn="QueryFilterFieldValue" velja="'Stalled'"/> <XSL:með-Gildi nafn="TotalItems" velja="$totalStalled"></XSL:með-Gildi> </XSL:kalla-sniðmát> <XSL:kalla-sniðmát nafn="ShowBar"> <XSL:með-Gildi nafn="BarDisplayLabel" velja="'In Process'"/> <XSL:með-Gildi nafn="BarPercent" velja="$percentInProcess"/> <XSL:með-Gildi nafn="QueryFilterFieldName" velja="'Status'"/> <XSL:með-Gildi nafn="QueryFilterFieldValue" velja="'In Process'"/> <XSL:með-Gildi nafn="TotalItems" velja="$totalInProcess"></XSL:með-Gildi> </XSL:kalla-sniðmát> </borð> </td> </tr> </borð> </XSL:annars> </XSL:velja> </XSL:sniðmát> <!-- This template does the work of displaying individual lines in the bar graph. You'll probably do most of your tweaking here. --> <XSL:sniðmát nafn="ShowBar"> <XSL:Gildi nafn="BarDisplayLabel" /> <!-- label to show --> <XSL:Gildi nafn="BarPercent"/> <!-- Percent of total. --> <XSL:Gildi nafn="QueryFilterFieldName"/> <!-- Used to jump to the query & filter --> <XSL:Gildi nafn="QueryFilterFieldValue"/> <!-- Used to jump to the query & filter --> <XSL:Gildi nafn="TotalItems" /> <!-- total count of this barlabel --> <tr> <!-- The bar label itself. --> <td flokki="ms-formbody" breidd="30%"> <!-- This next set of statements builds a query string that allows us to drill down to a filtered view of the underlying data. We make use of a few things here: 1. We can pass FilterField1 and FilterValue1 to a list to filter on a column. 2. SharePoint is passing a key parameter to us, ListUrlDir that points to the underlying list against which this DVWP is "running". Isn't XSL fun? --> <XSL:texta disable-framleiðsla sleppi=""> <![CDATA[<a href="]]></XSL:texta> <XSL:gildi-af velja="$ListUrlDir"/> <XSL:texta disable-framleiðsla sleppi=""><![CDATA[?FilterField1=]]></XSL:texta> <XSL:gildi-af velja="$QueryFilterFieldName"/> <XSL:texta disable-framleiðsla sleppi=""><![CDATA[&FilterValue1=]]></XSL:texta> <XSL:gildi-af velja="$QueryFilterFieldValue"/> <XSL:texta disable-framleiðsla sleppi=""><![CDATA[">]]></XSL:texta> <XSL:gildi-af velja="$BarDisplayLabel"/> <XSL:texta disable-framleiðsla sleppi=""><![CDATA[</a>]]></XSL:texta> <!-- The next bit shows some numbers in the format: "(total / % of total)" --> (<XSL:gildi-af velja="$TotalItems"/> / <!-- This creates a nice percent label for us. Takk, Microsoft! --> <XSL:kalla-sniðmát nafn="percentformat"> <XSL:með-Gildi nafn="percent" velja="$BarPercent"/> </XSL:kalla-sniðmát>) </td> <!-- Lokum, emit a <td> tag for the bar itself.--> <td> <borð cellpadding="0" cellspacing="0" landamæri="0" breidd="{round($BarPercent*100)+1}%"> <tr bgcolor="red"> <XSL:texta disable-framleiðsla sleppi=""><![CDATA[&nbsp;]]></XSL:texta> </tr> </borð> </td> </tr> </XSL:sniðmát> <!-- This is taken directly from some XSL I found in an MS template. --> <XSL:sniðmát nafn="percentformat"> <XSL:Gildi nafn="percent"/> <XSL:velja> <XSL:þegar próf="snið-númer($percent, '#,##0%;-#,##0%")= 'NaN'">0%</XSL:þegar> <XSL:annars> <XSL:gildi-af velja="snið-númer($percent, '#,##0%;-#,##0%")" /> </XSL:annars> </XSL:velja> </XSL:sniðmát> </XSL:stílsíðu>

The Results:

The XSL from above generates this graph:

mynd

Drill down to the underlying data by clicking on the status code:

mynd

Concluding Thoughts:

Can This Be Generalized?

I love this graphing concept, but I hate the fact that I have to go in and do so much hand-coding. I’ve given a little thought to whether it can be generalized and I’m optimistic, but I’m also a little fearful that there may be a brick wall somewhere along the path that won’t offer any work-around. If anyone has some good ideas on this, please make a note in the comments or email mig.

Vertical Graphs:

This is a horizontal bar graph. It’s certainly possible to create a vertical graph. We just need to change the HTML. I would start the same way: Create an HTML representation of a vertical bar graph and then figure out how to get that via XSL. If anyone is interested in that, I could be persuaded to try it out and work out the kinks. If someone has already done that, please let me know and I’ll gladly link to your blog 🙂

I think that challenge with a vertical graph is that the labels for the graph are more difficult to manage, but certainly not impossible.

Field Name Gotcha’s:

There are at least two things to look out for with your field names.

Fyrsta, a field name with a space has to be escaped in the XSL. This will probably be an issue here:

        <XSL:breytu nafn="totalProposed" 
velja="count(/dsQueryResponse/Rows/Row[normalize-space(@Status) = 'Proposed'])" />

If your "Status" column is actually named "Status Code" then you need to reference it as "Status_x0020_Code":

   <XSL:breytu nafn="totalProposed" 
velja="count(/dsQueryResponse/Rows/Row[normalize-space(@Status_x0020_Code) = 'Proposed'])" />

Annað, and I’m a little fuzzy on this, but you also need to be on the alert for field name changes. If you name your field "Status Code" and then later on, rename it to "AFE Status", the "internal name" does not change. The internal name will still be "Status Code" and must be referenced as "Status_x0020_Code". The "other resources" links may help diagnose and correct this kind of problem.

About that Color:

I picked "red" because it’s pleasing to me at the moment. It would not be a big deal to show different colors so as to provide more than just a visual description of a number, but to also provide a useful KPI. Til dæmis, if the percentage of "stalled" AFE’s is > 10% then show it red, otherwise show it in black. Nota <XSL:velja> to accomplish this.

Other Resources:

Happy transforming!

<endir />

Gerast áskrifandi að bloggið mitt!

OM Núverandi gögn með Custom List (eða, Enn ein OM Gögn Displayor [eins Yacc, en mismunandi])

Í dag, I spent a handful of hours tracking down the root cause behind the message "The column name that you entered is already in use or reserved. Choose another name."

Súlan í viðkomandi gæti skapað, eytt og aftur búið í öðru umhverfi, so I knew it wasn’t a reserved name. Hins, I simply couldn’t find the column anywhere via the standard SharePoint user interface at any site in the site collection.

I posted to MSDN forums here and the indomitable Andrew Woodward pointed me in the direction of the underlying object model data.

I went off to codeplex to find some tools that would help me peer into the underlying OM data and help me locate the trouble.

I tried several tools and they were very cool and interesting but in the end, the UI wasn’t good enough for my purpose. I’m not criticizing them by any means, but clearly the tool-makers didn’t have my problem in mind when they created their UI :). Most people seem to be investing a fair amount of time and effort in creating workstation / client applications that provide tree views, right-click context menus and so forth. These are nice and all, but it’s a lot of work to create a top-of-the-line user experience that is also very flexible.

I really needed an answer to this problem. It occurred to me that if I could get all of the site columns in the site collection into a custom list, I could filter, sort and create views that would help me find this supposedly existing column (which it did, BTW). I went ahead and did that and an hour or two later, had all my site columns loaded into a custom list with grouping, sorting and so forth. I found my answer five minutes later.

If and when I successfully take over the world, I think I will decree that all SharePoint tools providers must seriously consider surfacing their object model data in a custom list. That way, I have the power to search any way I want (constrained, auðvitað, by standard sharepoint features).