Hi,
I am new in xslt ,i want to remove any tag from xml file with using xslt .
Can anybody assit me.
Thanks in Advance.
Niranjan Kumar
My XMl file:-

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="emp.xsl"?>
<company>

<employee id="1">
<name>Niranjan<p>tkadakdk sadfafk ff</p></name>
<roll>1</roll>
<contact>Delhi</contact>
</employee>

<employee id="2">
<name>brijesh</name>
<roll>1</roll>
<contact>Noida</contact>
</employee>

<employee id="3">
<name>Rohit</name>
<roll>3</roll>
<contact>Gurgaon<p>rrrr ddd ssss</p></contact>
</employee>

</company>

DESIRED OUTPUT:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="emp.xsl"?>
<company>

<employee id="1">
<name>[B]Niranjan tkadakdk sadfafk ff[/B]</name>
<roll>1</roll>
<contact>Delhi</contact>
</employee>

<employee id="2">
<name>brijesh</name>
<roll>1</roll>
<contact>Noida</contact>
</employee>

<employee id="3">
<name>Rohit</name>
<roll>3</roll>
<contact>[B]Gurgaon rrrr ddd ssss[/B]</contact>
</employee>

</company>

Edited 6 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

Is it me, but I don't any difference between the 2 XML documents. Not sure what you want your transformation to do.

<name>Niranjan<p>tkadakdk sadfafk ff</p></name>

I want to remove <p> </p> tag from my xml document.

When it comes to XSLT, you want to write a template for each rule that you want. So in this case, you want to duplicate the original document and remove the <p> nodes.

Use the identity template to copy the original document. Then write a template rule for the <P> node that does nothing.

This XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<!--  Identity Temaplte -->
	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>

	<!-- Rule for <p> -->
	<xsl:template match="p" />

</xsl:stylesheet>

Produce this output:

<?xml version='1.0' ?>
<company>
	<employee id="1">
		<name>Niranjan</name>
		<roll>1</roll>
		<contact>Delhi</contact>
	</employee>

	<employee id="2">
		<name>brijesh</name>
		<roll>1</roll>
		<contact>Noida</contact>
	</employee>

	<employee id="3">
		<name>Rohit</name>
		<roll>3</roll>
		<contact>Gurgaon</contact>
	</employee>
</company>

Thanks a lot Dear.But i don't want to remove datas within <p> tags.

Thanks. again for ur good suggestions.

That's fine just change the rule for the <p> tags. Instead of doing nothing just copy the data insde the tags.

<xsl:template match="p" >
     <xsl:value-of select="."/>
</xsl:template>

BTW, these are really basic questions about the function of XSLT. You should read a book or go through online tutorials, all these could be answered there.

Edited 6 Years Ago by iceandrews: n/a

This article has been dead for over six months. Start a new discussion instead.