Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selecting the value of "type" attribute from XML file using XSLT

XML:

<laptop category="business">
        <name lang="en">HP Pavilion 15</name>
        <color>Silver</color>
        <processor>i5-1135G7</processor>
        <price type ="pln">3200</price>
        <price type ="usd">795</price>
        <price type ="euro">700</price>
</laptop>

XSL:

<h2><xsl:value-of select="name"/></h2>
<p>Color: <xsl:value-of select="color"/></p>
<p>Processor: <xsl:value-of select="processor"/></p>

I want to show as above, 3 different prices in XSL based on attribute type, how can i do it? Please help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The question is not entirely clear.

To show a specific price, you could use a predicate – for example (from the context of laptop), the instruction:

<xsl:value-of select="price[@type='pln']"/>

will return 3200.

To show all prices, you could something like:

<xsl:for-each select="price">
    <p>
        <xsl:text>Price: </xsl:text>
        <xsl:value-of select="."/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="@type"/>
    </p>
</xsl:for-each>

to get:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading