Modularizing XSLT code (extract file name from path)
Few days back I came across a requirement where I had to determine the name of a file given the absolute path. Had it been java or any other popular programming language I could just tokenize the path with the directory separator character ("/" or "") and taken the last token. However doing it in XSLT 1.0 was bit tricky. A recursive function (templates in case of XSLT 1.0 ) call was required."substring-after" function gives the part of the string after the first occurrence of a given delimiter.
[sourcecode language="xml"]
<xsl:template name="fileName">
<xsl:param name="path" />
<xsl:choose>
<xsl:when test="contains($path,'')">
<xsl:call-template name="fileName">
<xsl:with-param name="path" select="substring-after($path,'')" />
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($path,'/')">
<xsl:call-template name="fileName">
<xsl:with-param name="path" select="substring-after($path,'/')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$path" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
[/sourcecode]
And to call above code , we have to write the following fragment
[sourcecode language="xml"]
<xsl:call-template name="fileName">
<xsl:with-param name="path" select="D:codetest.txt"/>
</xsl:call-template>
[/sourcecode]
If XMLT 2.0 is available the above job is much easier using
[sourcecode language="xml"]
<xsl:template name="fileName">
<xsl:param name="path" />
<xsl:choose>
<xsl:when test="contains($path,'')">
<xsl:call-template name="fileName">
<xsl:with-param name="path" select="substring-after($path,'')" />
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($path,'/')">
<xsl:call-template name="fileName">
<xsl:with-param name="path" select="substring-after($path,'/')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$path" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
[/sourcecode]
And to call above code , we have to write the following fragment
[sourcecode language="xml"]
<xsl:call-template name="fileName">
<xsl:with-param name="path" select="D:codetest.txt"/>
</xsl:call-template>
[/sourcecode]
If XMLT 2.0 is available the above job is much easier using
base-uri()
... [Trackback]
ReplyDelete[...] There you will find 23381 more Infos: neilghosh.com/2012/08/20/modularizing-xslt-code-extract-file-name-from-path/trackback/ [...]
Grow Tall and Loss your weight Easily. Visit us at http://goo.gl/DQOdmg and Get it!
ReplyDeleteKami merupakan Apotek Obat Online Terlengkap yang menjual berbagai macam obat peninggi badan dan obat pelangsing badan dengan jamianan keaslian produk. Kunjungi kami di http://goo.gl/DQOdmg dan dapatkan peninggi dan pelangsing badan dengan harga Grosir…
הדרכים המומלצות לעשיית כסף מהבית הדרכים המומלצות לעשיית כסף מהבית
ReplyDeleteהדרכים המומלצות לעשיית כסף מהבית
password resetter
ReplyDelete[...]check below, are some totally unrelated websites to ours, nonetheless, they're most trustworthy sources that we use[...]
car crashes
ReplyDelete[...]just beneath, are many completely not related websites to ours, even so, they're surely worth going over[...]
car crashes
ReplyDelete[...]one of our visitors just lately proposed the following website[...]
best of vines
ReplyDelete[...]the time to study or visit the material or websites we've linked to beneath the[...]
My Source These kind of post are always inspiring and I prefer to check out quality content so I happy to unearth many first-rate point here in the post, writing is simply huge, thank you for the post
ReplyDeleteThese kind of post are always inspiring and I prefer to check out quality content so I happy to unearth many first-rate point here in the post, writing is simply huge, thank you for the post
Website maintenance
ReplyDeleteIt's nearly impossible to find educated people about this subject, however, you sound like you know what you're talking about! Thanks
The Birch of the Shadow
ReplyDeleteI feel there might be considered a number of duplicates, but an exceedingly handy record! I have tweeted this. Several thanks for sharing!
Souls in the Waves
ReplyDeleteGood Morning, I just stopped in to visit your website and considered I would say I appreciated myself.
The Silent Shard
ReplyDeleteThis tends to likely be really handy for a few within your work opportunities I intend to do not only with my blog but
The Birch of the Shadow
ReplyDeleteI feel there may possibly be considered a handful of duplicates, but an exceedingly helpful list! I have tweeted this. Numerous thanks for sharing!
Healing's Dragon
ReplyDeleteto search out problems to further improve my site!I suppose its ok to help make utilization of a few of the principles!!
Whispering Misty
ReplyDeleteSo sorry you may pass up the workshop!
The Silent Shard
ReplyDeleteThis can almost certainly be pretty beneficial for a few of the employment I decide to you should not only with my blog site but
obat sipilis denature indonesia
ReplyDeleteObat sipilis ampuh dari CV. Denature Indonesia merupakan salah satu produk herbal terpercaya untuk penyembuhan penyakit sipilis dengan cepat dan aman tanpa efek samping ataupun ketergantungan obat. Hal tersebut telah dibuktikan dengan terdaftarnya prod…
Souls in the Waves
ReplyDeleteExcellent Morning, I just stopped in to visit your site and thought I'd say I loved myself.
Without a secure wireless network, a hacker can see what you're doing
ReplyDeleteon your network and could install malicious software leaving you open to identity theft.
It's not clear if that cheaper model will be available in the US though.
4) Unlike WEP, WPA has a 48-bit IV, which enables nearly 500 trillion key combinations.
Really enjoyed this update, is there any way I can get an alert email every time you write a fresh post?
ReplyDeleteThey can often offer many great advantages that some
ReplyDeleteof the smaller vinyl banners cannot. Go through these
fields and fill in what you need to create your banner category.
In this menu, you will need to click the Banners link.
Hey guys !
ReplyDeleteI hanker after to launch my blog : http://flyfire06.legtux.org
This is a trifling news and tips blogs
So lets obstruct him in ;)
Set up a acute epoch :)
The Birch of the Shadow
ReplyDeleteI believe there might become a several duplicates, but an exceedingly handy list! I've tweeted this. Quite a few thanks for sharing!
Thang May Kieng Can Thoi Trang In Phu Nu
ReplyDeleteAttractive element of content. I just stumbled upon your blog and in accession capital to claim that I acquire actually enjoyed account your blog posts.
ReplyDeleteAny way I will be subscribing on your augment and even I achievement you get entry to persistently fast.