Txheej txheem cej luam thiab lub hom phiaj
Mus rau ntawm lub box, NTXHUAB’ Cov lus nug qhov Web Tshooj (CQWP) nws tau qhia nyob rau hauv ib daim ntawv teev hom, zoo li mus nrhiav tau. Nws tseem tau los tso saib qhov txheeb xyuas tau ib daim phiaj hom ntawv (i.e. Hom ntawv rooj HTML). Yog tawm tswv yim daim phiaj rau tej yam zoo. Kuv piav li cas after ntawd nyhuv hauv no Tshooj.
Lag luam Scenario
Kuv tau ua hauj lwm nrog ib tug neeg rau ib tug thoob plaws enterprise NTXHUAB rollout. Peb muaj tsim lawv taxonomy xws tias tej yaam num yog thawj class pej xeem nyob hauv lub hierarchy thiab muaj nyias qhov chaw saum theem. Yog ib qhov tswj khaws ib daim ntawv teev singleton uas yog ib qhov kev qhia, xws li lub npe, nyiaj txiag, cov kev tsim tiav tas hnub, nyiaj ntxiv thiab lwm yam kev teb. Yog "singleton" Kuv yog ib tug kev cai SharePoint sau guaranteed tau muaj cov yam khoom no tsuas muaj ib. Simplistically, nws zoo li no:
Txoj kev mus kom ze yog npaum li cas tau tib yam li koj piav ntawm no (http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!447.entry). Cov CQWP siv ib XSL transform kom emit HTML rau qhov browser mus kav.
Ib txwm kuv envision hom kab mob qhov tshwm sim ua ntej nyiab loj mus rau lub XSL vim XSL yog ib tug npau suav phem. Ntawm no yog kuv yam tshwm sim:
HTML li no generates uas raug:
|
<html>
<lub cev>
<chaw>
<cov lus ciam teb= 1>
<!-- Hmong-->
<tr bgcolor= xiav>
<Td><Font xim= dawb><b>Qhov project Name</b></Font></Td>
<Td dlhos= txoj cai><Font xim= dawb><b>Sau rau hnub tim</b></Font></Td>
<Td dlhos= txoj cai><Font xim= dawb><b>Nyiaj txiag</b></Font></Td>
<Td dlhos= txoj cai><Font xim= dawb><b>Cov nqi</b></Font></Td>
<Td><Font xim= dawb><b>Zuag qhia tag nrho cov txheej xwm</b></Font></Td>
</tr>
<tr>
<Td>Rov wire computer chav.</Td>
<Td dlhos= txoj cai>02/01/08</Td>
<Td dlhos= txoj cai>22,500.00</Td>
<Td dlhos= txoj cai>19,000.00</Td>
<Td>Dauv</Td>
</tr>
<tr>
<Td>Ntaub ntawv servers rau SQL Upgrade</Td>
<Td dlhos= txoj cai>04/01/08</Td>
<Td dlhos= txoj cai>7,500.00</Td>
<Td dlhos= txoj cai>0.00</Td>
<Td>Los</Td>
</tr>
</cov lus>
</chaw>
</lub cev>
</html>
|
Mus kom ze
Ua raws li cov kauj ruam yuav tsim tau rau daim phiaj:
- Taw rau Cheebtsam ntawm hauv daim phiaj (natwm/txhua).
- Txhais kom meej thiab tsim nyog kawm ntawv txhua.
- Tsim cov chaw sub rau qhov tej yaam num thiab singleton npe.
- Ntxiv ntawm CQWP mus rau ib qhov web page thiab configure mus nrhiav koj lub npe.
- Hloov cov CQWP XML sau mus rau txhua yam.
- Hloov tus XSL yuav ua tau kom muaj ib lub rooj.
Kuv yuav mloog zoo hauv tus xovtooj rau. Ib ntawm plaub numbers ncaj nraim thiab tej yam uas muaj neeg siv CQWP twb tau. Naj npawb 5 lawm documented zoo los ntawm lwm tus xws li no exhaustive txhaj tshuaj ntsuam laden Tshooj ntawm MSDN ntawm no (http://msdn2.microsoft.com/en-us/library/bb897399.aspx) thiab Heather tus Xatau-ntoos lub blog ntawm no (http://www.heathersolomon.com/blog/articles/CustomItemStyle.aspx).
Ceev And Bolts
Pib thiab kev nrhiav ib tug los ntawm as per rau cov ntaub ntawv MSDN thiab Heather tus Xatau-ntoos lub Tshooj tsib.
Thaum no tus taw tes, koj twb ua ntxiv koj CQWP mus rau sab thiab koj muaj koj <CommonViewFields> configured li tsim nyog.
Raws li cov kauj ruam li ib txwm, Kuv txais tau kev kuaj intermediate:
1. Tsim ib cov hom, templatized kev cai sau ntawd cov hom thiab ob qhov chaw. Ntawm no yog cov hom:
Ntawm no yog qhov chaw qauv:
2. Ntxiv rau qhov CQWP tom qab tsim kuv ib qhov subsites thiab singleton yog ib qhov kev npe:
3. Ntxiv tag nrho cov ntxiv kuv xav tau ntawm cov <CommonViewFields>:
<khoom lub npe="CommonViewFields" hom="hlua">Project_x0020_Name;Project_x0020_Expenses;Project_x0020_Status;Project_x0020_Start_x0020_Date;Project_x0020_End_x0020_Date;Project_x0020_Budget</khoom>
Ceeb toom tias kuv tau ua kom tag nrho cov cuab yeej teb ntawm ib tug kab los nws yuav tsis ua hauj lwm (CQWP xav qhia kuv tias cov lus nug rov qab tsis khoom).
4. Thaum no tus taw tes, mov kom dhau MSDN tsab xov xwm thiab flip ntawm nyob rau tshooj Heather tus Xatau-ntoos lub. Ua raws li nws cov kauj ruam pib ze rau ruam #5 los ua ib customized / unghosted version of ItemStyle.xsl. Kuv ua raws li cov lus qhia txog tus Heather, saum ntawm cov kauj ruam 11 thiab tau kuaj intermediate:
4.1: Kuv tus XSL template npe raws li nram no:
<xsl:Template npe = "daim phiaj" phim = "tshais[@Style = 'Daim phiaj']" hom = "itemstyle">
Kuv yuav ib nyuag kuj hloov nws pom tias <xsl:rau-ib …> yog muab ib <br /> lossis mus muab tov:
<xsl:rau-ib xaiv="@*">
P:<xsl:tus nqi-ntawm xaiv="lub npe()" /><br/>
</xsl:rau-ib>
4.2: Kuv hloov hauv cov qhov Web site, mus zoo li thiab xaiv daim kuv "phiaj" style:
Ntawm no yog cov siv qhov kev hloov thiab kev pab:
Peb pom tau ntawm qhov saum no uas teb peb xav (Peb tes num lub npe, nqi, xwm txheej, yam) yog muaj nyob rau peb siv thaum peb emit cov HTML. Tsis tas li ntawd, peb pom cov npe uas peb yuav tsum reference cov txhua hauv lub XSL. Piv txwv, peb reference Project txheej xwm li "Project_x005F_x0020_Name".
Thaum no tus taw tes, peb ncaim ntawm Heather tus blog thiab ntawm lub lub xub pwg nyom ntawm no giants, Kuv tus kheej lub ntsis ntxiv kuv.
ContentQueryMain.xsl
CEEB TOOM: Thaum muaj kev hloov rau ob ContentQueryMain.xsl li no ItemStyle.xsl, koj yuav tau xyuas cov ntaub ntawv qaum rau ua ntej koj mus ntsib cov nyhuv koj hloov.
Mus rau daim phiaj vaj, NTXHUAB siv ob yam XSL ntaub ntawv los ua cov ntsiab peb pom los ntawm ib tug CQWP. Meskas tus me ntsis dhau los tso zis ntau lawm, peb hloov ItemStyle.xsl. NTXHUAB yeej siv lwm daim ntawv XSL, ContentQueryMain.xsl yuav nyob tau nrog ItemStyle.xsl Meskas cov HTML. Raws li implies lub npe, ContentQueryMain.xsl yog "loj lub" XSL controls qhov txaus zuag qhia tag nrho cov neeg txhais lus. Nws iterates kev los ntawm tag nrho cov kabmob khoom thiab kis tau ib tug los ntawm ib tug mus templates hauv ItemStyle.xsl. Peb mam li hloov ItemStyle.xsl Meskas tus qhib <cov lus> lossis ua ntej emitting rau thawj kab ntawv thiab kaw <cov lus> lossis tom qab emitting rau kab kawg. Yuav ua kom tiav no, ContentQueryMain.xsl hloov mus rau kis ob tug tsis tau rau daim peb "phiaj" Template hauv ItemStyle.xsl, "lub xeem leej" thiab "leej tam sim no". ItemStyle.xsl siv no rau conditionally emit tus cim npe tsim nyog.
Siv cov txheej txheem Heather tus Xatau-ntoos lub, Peb nrhiav ContentQueryMain.xsl. Nws nyob hauv qhov chaw qub li ItemStyle.xsl. Qhov tshuaj ntsuam txhaj yuav pab:
Peb yuav tau ua cov nram qab no hloov:
- Hloov ib tus xsl template, "CallItemTemplate" uas tau invokes peb daim phiaj template hauv ItemStyle.xsl. Peb yuav kis tau ob tsis mus rau daim phiaj template kom nws yuav muaj cov ntaub ntawv uas nws xav kom neeg conditionally qhib thiab kaw <cov lus> cim npe.
- Hloov dua me ntsis uas hu ua "CallItemTemplate lub ContentQueryMain.xsl" yuav kis tau "LastRow ib" parameter kom cov LastRow uas tau kis rau peb cov template daim phiaj.
Nrhiav tus template npe hu ua "OuterTemplate.CallItemTemplate" qhia los ntawm cov hlua:
<xsl:Template lub npe="OuterTemplate.CallItemTemplate">
Tag nrho cov template hloov raws li nram no:
|
<xsl:Template lub npe="OuterTemplate.CallItemTemplate">
<xsl:param lub npe="CurPosition" />
<!--
Ntxiv "LastRow cov" parameter.
Peb tsuas siv cov khoom style pass hauv yog "Daim phiaj".
-->
<xsl:param lub npe="LastRow" />
<xsl:xaiv>
<xsl:Thauj tw ntsuam xyuas="@Style = 'NewsRollUpItem'">
<xsl:thov templates xaiv="." hom="itemstyle">
<xsl:nrog param lub npe="EditMode" xaiv="$cbq_iseditmode" />
</xsl:thov templates>
</xsl:Thauj tw>
<xsl:Thauj tw ntsuam xyuas="@Style = 'NewsBigItem'">
<xsl:thov templates xaiv="." hom="itemstyle">
<xsl:nrog param lub npe="CurPos" xaiv="$CurPosition" />
</xsl:thov templates>
</xsl:Thauj tw>
<xsl:Thauj tw ntsuam xyuas="@Style = 'NewsCategoryItem'">
<xsl:thov templates xaiv="." hom="itemstyle">
<xsl:nrog param lub npe="CurPos" xaiv="$CurPosition" />
</xsl:thov templates>
</xsl:Thauj tw>
<!--
Tshaj xav tam sim no thiab cov lastrow rau ntawm daim phiaj itemstyle.xsl template.
ItemStyle.xsl yuav siv uas emit rau txoj kev qhib thiab kaw <cov lus> cim npe.
-->
<xsl:Thauj tw ntsuam xyuas="@Style = 'Daim phiaj'">
<xsl:thov templates xaiv="." hom="itemstyle">
<xsl:nrog param lub npe="CurPos" xaiv="$CurPosition" />
<xsl:nrog param lub npe="Kav" xaiv="$LastRow" />
</xsl:thov templates>
</xsl:Thauj tw>
<xsl:txwv tsis pub>
<xsl:thov templates xaiv="." hom="itemstyle">
</xsl:thov templates>
</xsl:txwv tsis pub>
</xsl:xaiv>
</xsl:Template>
|
Cov lus qhia txog lub hom phiaj ntawm qhov kev hloov.
tau mas, "OuterTemplate.CallItemTemplate cov" nws tus kheej yog hu los ntawm lwm template. Nrhiav tus template ntawm searching rau qhov ntawv txoj hlua:
<xsl:Template lub npe="OuterTemplate.Body">
Scroll los ntawm cov lus qhia nyob rau hauv OuterTemplate.Body thiab cov LastRow parameter ntxig raws li nram no (qhia raws li ib tug saib nyob rau hauv italics):
<xsl:hu-template lub npe="OuterTemplate.CallItemTemplate">
<xsl:nrog param lub npe="CurPosition" xaiv="$CurPosition" />
<!-- Ntxig rau LastRow parameter. -->
<xsl:nrog param lub npe="LastRow" xaiv="$LastRow"/>
</xsl:hu-template>
Tom qab nov tag nrho, peb thaum kawg muaj yam teeb zoo zoo kom peb cov ItemStyle.xsl muaj emit <cov lus> cim npe rau qhov chaw uas koj txoj kev.
ItemStyle.Xsl
CEEB TOOM: Dua, nyob ItemStyle.xsl kos tom qab hloov yam koj pom cov nyhuv uas cov kev pauv.
Peb muaj tus ob tug paub tab ntawm no:
- Hloov hauv koj daim phiaj template. Koj tau daim ntawv/muab tshuaj txhuam hauv qab no txij.
- Ntxiv ib co mumbo jumbo sab nraud lub ntsiab template txhais tias enables "formatcurrency" Template mus ua hauj lwm. (Koj yuav qhia tau tias kuv muaj ib cov neeg kov tenuous XSL).
Ua ntej, ze rau saum ItemStyle.xsl, ntxiv cov kab no:
<!-- Tej mumbo jumbo uas peb tso saib tuaj enables. txiaj. -->
<xsl:hom zauv lub npe="cov neeg ua haujlwm" ntiv="D" />
<xsl:Template lub npe="Neej ntawd" phim="*" hom="itemstyle">
Faj seeb txog tias kuv ntxiv tias yuav ua ntej mus ncaj rau <xsl:Template npe = "Default" …> txhais.
Tom ntej, rov qab mus saib peb daim phiaj template. Menyuam mos liab cov daim phiaj template sim cov cai nram qab no. Nws yog muab commented, tab sis tsis txhob yig email rau kuv los sis tawm lus rau kuv blog yog hais tias koj muaj lus nug.
|
<xsl:Template lub npe="Daim phiaj" phim="Tshais[@Style = 'Daim phiaj']" hom="itemstyle">
<!--
ContentMain.xsl kis tau CurPos thiab xeem.
Peb siv cov no los conditionally emit rau txoj kev qhib thiab kaw <cov lus> cim npe.
-->
<xsl:param lub npe="CurPos" />
<xsl:param lub npe="Kav" />
<!-- Cov tsiaj ntawv nram qab no yog los ntawm tus txheem ItemStyle.xsl unmodified -->
<xsl:kuj sib txawv thiab lub npe="SafeImageUrl">
<xsl:hu-template lub npe="OuterTemplate.GetSafeStaticUrl">
<xsl:nrog param lub npe="UrlColumnName" xaiv="'ImageUrl'"/>
</xsl:hu-template>
</xsl:kuj sib txawv thiab>
<xsl:kuj sib txawv thiab lub npe="SafeLinkUrl">
<xsl:hu-template lub npe="OuterTemplate.GetSafeLink">
<xsl:nrog param lub npe="UrlColumnName" xaiv="'LinkUrl'"/>
</xsl:hu-template>
</xsl:kuj sib txawv thiab>
<xsl:kuj sib txawv thiab lub npe="DisplayTitle">
<xsl:hu-template lub npe="OuterTemplate.GetTitle">
<xsl:nrog param lub npe="Npe" xaiv="@Title"/>
<xsl:nrog param lub npe="UrlColumnName" xaiv="'LinkUrl'"/>
</xsl:hu-template>
</xsl:kuj sib txawv thiab>
<xsl:kuj sib txawv thiab lub npe="LinkTarget">
<xsl:Yog hais tias ntsuam xyuas="@OpenInNewWindow = 'Tseeb'" >_blank</xsl:Yog hais tias>
</xsl:kuj sib txawv thiab>
<!--
Ntawm no peb txhais ib kuj sib txawv thiab, "tableStart". Qhov no muaj cov HTML uas peb siv txhais cov lus qhib cov qhov rooj li no rau cov ntawv qhia kiag. Nco ntsoov tias CurPos = 1, nws nrog cov HTML rau ib CDATA lossis.
Txwv tsis pub, nws yuav tau npliag.
Cov nqi no tableStart no emited txhua zaus ItemStyle hu ua ntawm ContentQueryMain.xsl.
-->
<xsl:kuj sib txawv thiab lub npe="tableStart">
<xsl:Yog hais tias ntsuam xyuas="$CurPos = 1">
<![CDATA[
<ciam teb lus = 1>
<tr bgcolor = "ntsuab">
<Td><xim Font = "dawb"><b>Qhov project Name</b></Font></Td>
<Td dlhos = "txoj cai"><xim Font = "dawb"><b>Sau rau hnub tim</b></Font></Td>
<Td dlhos = "txoj cai"><xim Font = "dawb"><b>Nyiaj txiag</b></Font></Td>
<Td dlhos = "txoj cai"><xim Font = "dawb"><b>Cov nqi</b></Font></Td>
<Td><xim Font = "dawb"><b>Zuag qhia tag nrho cov txheej xwm</b></Font></Td>
</tr>
]]>
</xsl:Yog hais tias>
</xsl:kuj sib txawv thiab>
<!--
Kuj sib txawv thiab lwm, tableEnd cias nyiaj thiab lub sij lub kaw lus lossis.
Raws li nrog tableStart, Nws yog emited. Qhov no yog vim li cas nws tus nqi yog raug conditionally based raws li qhov seb peb twb tau mus rau kab kawg ntawm ContentQueryMain.xsl.
-->
<xsl:kuj sib txawv thiab lub npe="tableEnd">
<xsl:Yog hais tias ntsuam xyuas="$CurPos = $Last">
<![CDATA[ </cov lus> ]]>
</xsl:Yog hais tias>
</xsl:kuj sib txawv thiab>
<!--
Nco ntsoov emit tus txheem ntawm tableStart. Yog hais tias qhov no yuav tsis tau rau thawj kab dhau rau peb ntawm ContentQueryMain.xsl, ces peb paub nws tus nqi yuav dawb paug.
Lov tes taw tso zis ntau escaping vim hais tias thaum twg tableStart nws tsis dawb paug, nws muaj xws li cov HTML uas peb xav tau nws los ntawm qhov browser. Yog peb tsis txhob hais XSL parser los lov tes taw rau cov zis escaping, nws yuav ua kom muaj khoom xws li"<cov lus>" hloov ntawm"<cov lus>".
-->
<xsl:tus nqi-ntawm xaiv="$tableStart" lov tes taw-zis-escaping="yog"/>
<tr>
<!--
P:Project_x005F_x0020_Name P:Project_x005F_x0020_End_x005F_x0020_Date P:Project_x005F_x0020_Budget P:Project_x005F_x0020_Expenses P:Project_x005F_x0020_Status
-->
<Td>
<xsl:tus nqi-ntawm xaiv="@Project_x005F_x0020_Name"/>
</Td>
<Td dlhos="txoj cai">
<xsl:tus nqi-ntawm xaiv="@Project_x005F_x0020_End_x005F_x0020_Date"/>
</Td>
<Td dlhos="txoj cai">
<xsl:hu-template lub npe="formatcurrency">
<xsl:nrog param lub npe="tus nqi" xaiv="@Project_x005F_x0020_Budget"></xsl:nrog param>
</xsl:hu-template>
</Td>
<Td dlhos="txoj cai">
<xsl:hu-template lub npe="formatcurrency">
<xsl:nrog param lub npe="tus nqi" xaiv="@Project_x005F_x0020_Expenses"> </xsl:nrog param>
</xsl:hu-template>
</Td>
<Td>
<xsl:tus nqi-ntawm xaiv="@Project_x005F_x0020_Status"/>
</Td>
<!--
Tag nrho cov nram no yog commented tawm hais yam.
Txawm li cas los, coj nws rov qab thiab stuff nws mus ua ib tug <Td> saib cov nyhuv.
-->
<!--
<div daim id = "linkitem" hoob = "item">
<xsl:Yog tias kuaj = "hlua-ntev($SafeImageUrl) != 0 ">
<div hoob = "duab-tsam-laug">
<ib tug href = "{$SafeLinkUrl}" TARGET = "{$LinkTarget}">
<img hoob = "duab-tas-dav" src = "{$SafeImageUrl}" xwm = "{@ImageUrlAltText}"/>
</ib tug>
</div>
</xsl:Yog hais tias>
<chav kawm ntawv div = "txuas yam">
<xsl:hu-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
<ib tug href = "{$SafeLinkUrl}" TARGET = "{$LinkTarget}" Title = "{@LinkToolTip}">
<xsl:tus nqi-kev xaiv = "$DisxslyTitle" />
</ib tug>
<div hoob = "hauj lwm">
<xsl:tus nqi-cov select="@Description" />
</div>
</div>
</div>
-->
</tr>
<!--
Emit kaw table lossis. Yog tias peb tsis nyob rau hnub kab,
qhov no yuav ua dawb paug.
-->
<xsl:tus nqi-ntawm xaiv="$tableEnd" lov tes taw-zis-escaping="yog"/>
</xsl:Template>
<xsl:Template lub npe="formatcurrency">
<xsl:param lub npe="tus nqi" xaiv="0" />
<xsl:tus nqi-ntawm xaiv='hom ntawv xov tooj($tus nqi, "$DDD,DDD,DDD.HNUB", "ua hauj lwm")' />
</xsl:Template>
|