RE: [xsl] XSL Remove part of a text inside TAG

Subject: RE: [xsl] XSL Remove part of a text inside TAG
From: "Buddhi D. Mahindarathne" <buddhi@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 7 Mar 2008 08:58:07 +0530
Hi all,
 I tried Mukul Gandhi's way, but it is not working for me. And I can't
use other packages as he requested because I can't package and
distribute those with my application. I have to use standard XSLT 1.0

So, I implemented following ...

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
	<xsl:template match="/">
		<xsl:apply-templates select="*"/>
	</xsl:template>
    <xsl:template match="@* | node()">
	<xsl:copy>
	  <xsl:apply-templates select="@* | node()"/>
	</xsl:copy>
    </xsl:template>
   <xsl:template match="VisualObject">
		<xsl:choose>
			<xsl:when test="@xsi:type='CBarCode'">
				<xsl:copy>
					<xsl:variable name="fontface"
select = 'FontFace'/>
					<xsl:call-template name="while">
						<xsl:with-param
name="foo" select="$fontface"/>
					</xsl:call-template>
				</xsl:copy>
			</xsl:when>
			<xsl:otherwise>
				<xsl:copy-of select="."/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

<xsl:template name="while">
	<xsl:param name="foo"/>
	<xsl:choose>
		<xsl:when test="fn:matches($foo ='\')">
			<xsl:variable name="newfoo"
select="fn:substring-after($foo,'\')"/>
			<xsl:call-template name="while">
				<xsl:with-param name="foo"
select="$newfoo"/>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$foo"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
</xsl:stylesheet>

But, to use those string functions I need to add a another NameSpace
xmlns:xsi="http://www.w3.org/2005/02/xpath-functions";

Since I already have one how I put another one there...??
Or any other ways of doing this... only with standard package..

- Buddhi -

-----Original Message-----
From: buddhi [mailto:buddhi@xxxxxxxxxxxxxxxxxxx]
Sent: Wednesday, March 05, 2008 3:01 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] XSL Remove part of a text inside TAG

Hi all,

Following is my xml file,

<?xml version="1.0"?>
<FileSerializeWrapper xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
  <Unit>Inches</Unit>
  <PanPoint>
    <X>0</X>
    <Y>0</Y>
  </PanPoint>
  <ZoomFactor>0</ZoomFactor>
  <FlowData>
    <VisualObject xsi:type="CProjectEx">
      <maxQSwitch>500</maxQSwitch>
      <Address>Laser Job</Address>
    </VisualObject>
    <TrueSideChildren>
      <FlowData>
        <VisualObject xsi:type="CLayerEx">
          <maxQSwitch>500</maxQSwitch>
          <Address>Laser Job.Layer</Address>
          <Name>Layer</Name>
          <Override>true</Override>
        </VisualObject>
        <FlowType>Layer</FlowType>
        <TrueSideChildren>
          <FlowData>
            <VisualObject xsi:type="CBarCode">
              <maxQSwitch>133</maxQSwitch>
              <Address>Laser Job.Layer.Barcode1</Address>
              <Name>Barcode1</Name>
              <Width>2.8144999999999953</Width>
              <DataString>CODE 39 TEXT</DataString>
              <EncodeData>
                <dBCHeight>0.5</dBCHeight>
                <dBCWidth>2.8144999999999953</dBCWidth>
                <szQRFmtAppIndicator />
              </EncodeData>
              <EnableHRText>true</EnableHRText>
              <FontFace>D:\Work\Phase
III\Executables\Fonts\TIMESNRO.FNT</FontFace>
              <IsBold>false</IsBold>
              <IsItalic>false</IsItalic>
              <FontHeight>0.08</FontHeight>
              <FontGap>0.02</FontGap>
              <HRTextAtTop>false</HRTextAtTop>
            </VisualObject>
            <ShapeName />
          </FlowData>
        </TrueSideChildren>
        <FalseSideChildren />
        <IsExpanded>true</IsExpanded>
        <EventDataCode />
        <ShapeName />
      </FlowData>
    </TrueSideChildren>
    <FalseSideChildren />
    <EventDataCode />
    <ShapeName />
  </FlowData>
</FileSerializeWrapper>

 Actually I want ONLY to remove a path from this tag,

<FontFace>D:\Work\Phase III\Executables\Fonts\TIMESNRO.FNT</FontFace>

In final xml file I want to appear it as this,

<FontFace>TIMESNRO.FNT</FontFace>

I tried so many ways, since I couldn't find mid,left, right string
functions with xsl, I couldn't get the expected out put. Following is my

xsl file. Can anyone please tell me how to do that.

My XSL file :

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
    <xsl:template match="/">
        <xsl:apply-templates select="*"/>
    </xsl:template>
    <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="VisualObject">
        <xsl:choose>
            <xsl:when test="@xsi:type='CBarCode'">
                <xsl:copy>
                </xsl:copy>
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy-of select="."/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

- Regards

- Buddhi -

Current Thread