Qeb Archives: XSLT

XSLT thiab jQuery Samples

Kuv tau raug ua ntau heev nyob ntawm XSLT thiab jQuery, thiab kuv yuav muab ib ob peb snippets uas lwm tus tau nrhiav pab yav thought.

Piv txwv 1: Emit yooj yim JavaScript / jQuery hauv XSLT:

<xsl:Template match = "tej yam" xml:chaw = "khaws cia">

  <!– Dawb paug tawm tau cov lus nug cov ntxaij lim dej tus phooj ywg thaum teb –>
  <Script yam = "ntawv nyeem/javascript">
    $(daim ntawv).npaj txhij(muaj nuj nqi(){
      $("#QueryFriendlyFilters").val("tas");
    });
  </tsab ntawv>

</xsl:Template>

Tus ntsis emits ib co JavaScript waits rau ntawm nplooj los suaj kaum rau nraum chaw thau khoom (vim tias tus $(daim ntawv).npaj txhij(…)) hu ces poob lawm tus nqi thaum teb ua QueryFriendlyFilters mus rau cov nqi literal "tas".

Piv txwv 2: Siv <xsl:Yog hais tias> saib "ntau dua",  "tsis tau muaj", yam.

<xsl:Template match = "tej yam" xml:chaw = "khaws cia">

  <div daim id = "fdcAllFilters">
 
    <xsl:yog test="@Count>0">
      <ntsua kev kawm = "fdcFilterLabel">Lim tam sim no:</ntsua kev>
    </xsl:Yog hais tias>

    <!– ntxiv khoom zoo li no. –>

</xsl:Template>

Saum cov snippet nug saib puas yog ib tug attribute npe hu ua "Suav" ntawm cov "tej yam" caij ntau dua zero.  XML hauv qab no yuav ua ib yam dab tsi zoo li:”

<yam suav = "5" />

Piv txwv 3: Iterate los ntawm tag nrho cov ntsiab, interspersing jQuery hu.

<!– Iterate los ntawm txhua lub lim thiab tso saib qhov tseeb  kev mus. –>
<xsl:rau-ib qho = "UserFilter">

  <hoob kawm = "FilterHref" href = "javascript:mySubmitPage('RemoveUserFilter','{@ID}’)">[X]</ib tug>

  <ntsua kev kawm = "fdcFilterLabel"><xsl:tus nqi-cov select="@FilterValue"/></ntsua kev>

  <Script yam = "ntawv nyeem/javascript">

    $(daim ntawv).npaj txhij(muaj nuj nqi(){
        <xsl:ntawv nyeem><![CDATA[$("#QueryFriendlyFilters").val( ($("#QueryFriendlyFilters").val() + " ]]></xsl:ntawv nyeem>\"<xsl:tus nqi-cov select="@FilterValue"/>\"<xsl:ntawv nyeem><![CDATA["));]]></xsl:ntawv nyeem>
    });

  </tsab ntawv>

</xsl:rau-ib>

Saum cov snippet yog tus tshaj txoj thiab tej zaum yuav muaj txoj kev uas yooj yim ua.

Lub XML qab no zoo roughly li no:

<UserFilter ID = "123" FilterValue = "xyzzy" />

Cov snippet no yog ntsuas los ntawm <UserFilter> o. 

Nws xub emits ib lub thauj tog rau nkoj tag uas thaum clicked invokes ib JavaScript zoo uas twb yog nyob rau sab, "mySubmitPage" thiab kis tau tus nqi ntawm ib lub attribute lub <UserFilter> ntawm hu ua "ID". 

Nws mam li emits ib co jQuery waits rau rau sab mus thauj khoom.  Tus jQuery siab thaum teb hu ua "QueryFriendlyFilters" los ntawm kev ntxiv cov nqi ntawm qhov FilterValue attribute.  Nco ntsoov txhua lub crazy <xsl:ntawv nyeem> thiab <![CDATA[ … ]]> khoom.

Tus ntawd yog nws, vam tias nws yuav pab!

</kawg>

Subscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin

Endlessly Nesting <div> Ntawv cim npe thiab jQuery

Qhov no xws li tej tus oddball npe nkawd, Kuv tsis paub hais tias nws yog yeej muaj nqis blogging txog, tab sis cov uas ib txwm tsis lawm ua ntej kuv, yog li no peb yuav mus Luag nyav

Kuv tabtom haujlwm rau ib qhov project uas kuv tabtom rub tau tej ntaub ntawv los ntawm ib tug mus nrhiav, packaging nws rau hauv ib cov lus XML thiab ces tus XML yog kawg transformed rau HTML ntawm XSLT.  Muaj coob heev jQuery muab kev koom tes, ib ntsis uas implements tej cov tabbing functionality.  Thaum twg koj nyem rau ntawm ib tug tab (tiag tiag, ib tug <div>), jQuery invokes .hide() thiab .show() nyob rau ntau yam divs (cov nplooj pib load downloads cov ntsiab lus txhua yam thiaj li muaj muaj tsis muaj postbacks qhov no).

Ib Rev teev dhau los, tus tab switching logic pib coj erratically thiab nws tsis qhia ib qho kuv tabs.  Kuv kawg tracked nws mus txog ntawd qhov internet explorer (tsawg) xav hais tias tus <div> cim npe nested deb deb, deb ntxaum dua intended.Tus tsim tawm toolbar yuav qhia:

-<div daim id = "Tab1Content">
  -<div>
    -<div>
      -<div daim id = "Tab2Content">
        -<div>
           …………………………
                   </div>  <— kaw thaum kawg uas qhia nws tag kev cia rau no!

Li ntawd, Yog hais tias kuv ua ib $("#Tab1Content").nkaum(), Kuv kuj xav nraim Tab2 thiab kuv yuav tsis pom Tab2 yog hais tias kuv tsis tau qhia Tab1.  Tau theej thiab Document lub chaws rau studio siv qhov muag saib thiab nws yuav tsom hauv ob sab qhov div phlu tuaj tag nrho nicely, li lawv thiab yuav tau ua, saib zoo li no:

-<div daim id = "Tab1Content">
  +<div>
  +<div>
-<div daim id = "Tab2Content">
  +<div>
  +<div>

Tuav kuv lub taub hau tiv thaiv phab ntsa ib pliag thiab pom tau tias nyob hauv lub txoos HTML code tau generating empty heev <div> cim npe, zoo li:

<lub cev>

  <div daim id = "Tab1Content">

    <div daim id = "row1" />
    <div daim id = "row2" />

  </div>

  <div daim id = "Tab2Content">

    <div daim id = "row1" />
    <div daim id = "row2" />

  </div>

</lub cev>

(Cov saum no yog waaaaaaaaaaaay oversimplified.  Qhov khoob div cim ua npe yog siv tau lig. Qee yam ntawm kuv <div> cim npe tau tag nrho cov ntsiab lus, tab sis coob tshaj ntawd twb tsis tau.  Kuv tuaj hauv realization uas kuv <xsl:rau-ib> kev tswj tau emitting lub luv-daim ntawv div tags thaum twg tus xsl:rau-ib tsis ' nrhiav tej ntaub ntawv no.  Kuv yuam ua qhov HTML saib mus rau hauv lub qhov zis, li:

image

 

Tom qab kuv puas tau tias, tag nrho cov div lub lined nicely thiab kuv tab switching pib ua hauj lwm.

Li ib txwm, Kuv vam tias qhov no yuav pab lwm tus neeg nyob hauv lub pinch.

</kawg>

Subscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin

Piv txwv: XSLT tsim HTML Href tus

Kuv twb tau ua me ntsis XSL khoom lately thiab xav tias kuv yuav muab sib dhos ib tug qauv rau kuv cov neeg siv yav tom ntej thiab uas tej zaum yuav nqis los rau peb sawv daws XSLT-ers ua ib tug nyob hauv cov internets.

Xav txog cov lus hauv qab no XML:

<FdcSearchTabsCollection suav = "2">
  <SearchTab daim ntawv lo = "kev lag luam" SortOrder = "00" daim ntawv lo = "Industries" SearchConstraints = "contenttype:Kev lag luam" TabID = "831b2a74-98c4-4453-8061-86e2fdb22c63" />
  <SearchTab daim ntawv lo = "txoj kev" SortOrder = "01" daim ntawv lo = "Practices" SearchConstraints = "contenttype:PracticeGroups" TabID = "678e206b-6996-421f-9765-b0558fe1a9c0" />
</FdcSearchTabsCollection>

Cov lus hauv qab no XSL snippet yuav tsim ib daim ntawv teev sorted txog hrefs tabs:

<xsl:Template match = "FdcSearchTabsCollection" xml:chaw = "khaws cia">
   
    <!– "Tagnrho cov" tab –>
    <ib tug href = "javascript:ViewTab('Txhua')">Saib tag nrho cov</ib tug>
   
    <!– Txhua tus neeg tab –>
    <!– Iterate los ntawm tag nrho cov Tabs thiab tso saib qhov tseeb  kev mus. –>
    <xsl:rau-ib qho = "SearchTab">
      <xsl:tsi select="@SortOrder"/>

      …
      <ib tug href = "javascript:ViewTab(‘{@ TabID}’)"><xsl:tus nqi-cov select="@Label"/></ib tug>
    </xsl:rau-ib>

    <br /> 
   

   </xsl:Template>

Nov yog qhov nws zoo li hauv SharePoint:

SNAGHTML78aa2cb

 

 

</kawg>

Subscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin