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