What is XSLT Element in XML
Posted in
XML | XSLT July 04, 2019
In this article you will learn what is XSLT Element in XML.
Here we define xsl:apply-imports element. The xsl:apply-imports element is used to define a template that can be applied to a node to produce a desired output display. There are no attributes in xsl:apply-imports elements. The element may contain zero of more xsl:with-param elements . Each selected node is processed using the best-match xsl:apply-imports defined for that node.The following XSLT elements is given below-
-
Syntax
<xsl:apply-imports />
The xsl:apply-imports element is used in conjunction with imported stylesheets.
Example
XML File: The XML source file, abc.xml. This data file defines three operations: add
(+
), sub
(-
) and mul
(*
)
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="abc.xsl"?>
<ops>
<desc>Some binary operations</desc>
<op name="add" symbol="+">
<operand>1</operand>
<operand>2</operand>
</op>
<op name="sub" symbol="-">
<operand>1</operand>
<operand>2</operand>
</op>
<op name="mul" symbol="*">
<operand>1</operand>
<operand>2</operand>
</op>
</ops>
|
Save it : abc.xml
Example
XSLT File:The main XSLT style sheet, abc.xsl. This file contains the template rules for the operations, including two <xsl:import>
elements. The imported style sheets perform the arithmetic and string operations on a given data source.
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.google.com/2000/XSL/Transform"
version="1.0">
<xsl:template match="op[@symbol='+']">
<xsl:value-of select="sum(operand)"/> (from arith.xsl)
</xsl:template>
<xsl:template match="op[@symbol='-']">
<xsl:value-of select="number(operand[1])-number(operand[2])"/>
(from arith.xsl)
</xsl:template>
<xsl:template match="op[@symbol='*']">
<xsl:value-of select="number(operand[1])*number(operand[2])"/>
(from arith.xsl)
</xsl:template>
</xsl:stylesheet>
|
Save it-abc.xsl
Example
Imported XSLT File
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.google.com/2000/XSL/Transform"
version="1.0">
<xsl:template match="desc">
<DIV>
<xsl:value-of select="."/>
</DIV>
</xsl:template>
<xsl:template match="op[@name='add']">
<xsl:value-of select="operand[1]"/>
<xsl:value-of select="operand[2]"/> (from str.xsl)
</xsl:template>
<xsl:template match="op[@name='mul']">
<xsl:value-of select="operand[2]"/>
<xsl:value-of select="operand[1]"/> (from str.xsl)
</xsl:template>
</xsl:stylesheet>
|
Save it-math.xsl
Out Put
You should get the following output:
Some binary operations
1-2 = -1 (from math.xsl)
Further Readings
You may also want to read these related articles :
Ask Your Question
Ask Your Question Got a programming related question? You may want to post your question here
Programming Answers here