I'm still searching, but I haven't found yet the way to perform something like this:
xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- some other templates -->
<xsl:template match="IMAGE">
<img src="src_attribute_to_be_read_from_the_xml_file.jpg"/>
</xsl:template>
</xsl:stylesheet>
In my Xml <IMAGE>
tags, the text value is the filename that should be inserted in the string src_attribute_to_be_read_from_the_xml_file.jpg
when processed by this Xslt file.
Have you any idea to perform this ?
The standard way to transform XML data into other formats is by Extensible Stylesheet Language Transformations (XSLT). You can use the built-in XSLTRANSFORM function to convert XML documents into HTML, plain text, or different XML schemas. XSLT uses stylesheets to convert XML into other data formats.
XSLT <xsl:variable> The <xsl:variable> element is used to declare a local or global variable. Note: The variable is global if it's declared as a top-level element, and local if it's declared within a template. Note: Once you have set a variable's value, you cannot change or modify that value!
Attributes can be added or modified during transformation by placing the <xsl:attribute> element within elements that generate output, such as the <xsl:copy> element. Note that <xsl:attribute> can be used directly on output elements and not only in conjunction with <xsl:element> .
The <xsl:value-of> element is used to extract the value of a selected node.
You use xsl:attribute
:
<img>
<xsl:attribute name="src">
<xsl:value-of select="you path here"/>
</xsl:attribute>
</img>
It should also be possible to use
<img src="{some expression here}" />
According to the specification this is called a attribute value template and should always work (i.e. both XSLT 1.0 and 2.0). Nice. Now I learned something too.
Alternatively you can use XSL template:
<xsl:template match="image">
<xsl:element name="IMG">
<xsl:attribute name="src">
<xsl:value-of select="your_path"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="your_title"/>
</xsl:attribute >
</xsl:element>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With