Reputation: 45
I am new to using XSLT and I am struggling with a problem . I want to print out the text between the xml tags.
XML code
<?xml version="1.0" encoding="UTF-8"?>
<generic-cv:generic-cv xmlns:generic-cv="http://www.cihr-irsc.gc.ca/generic-cv/1.0.0" lang="en" dateTimeGenerated="2014-05-30 11:40:50">
<section id="f589cbc028c64fdaa783da01647e5e3c" label="Personal Information">
<section id="2687e70e5d45487c93a8a02626543f64" label="Identification" recordId="4f7c2ebd789f407b939e05664f6aa7c0">
<field id="ee8beaea41f049d8bcfadfbfa89ac09e" label="Title">
<lov id="00000000000000000000000000000318">Mr.</lov>
</field>
<field id="5c6f17e8a67241e19667815a9e95d9d0" label="Family Name">
<value type="String">ali</value>
</field>
<field id="98ad36fee26a4d6b8953ea764f4fed04" label="First Name">
<value type="String">Hara</value>
</field>
<field id="4ca83c1aaa6a42a78eac0290368e70f3" label="Middle Name">
<value type="String"/>
</field>
<field id="41ed5ea3ae974428b3fcb592161b6423" label="Date of Birth">
<value format="MM/dd" type="MonthDay">8/23</value>
</field>
<field id="2b72a344523c467da0c896656b5290c0" label="Correspondence language">
<lov id="00000000000000000000000000000054">English</lov>
</field>
</section>
</section>
xslt code
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>Xml Convertor</title>
</head>
<body>
<h2><b> Personal Information</b></h2>
<ul>
<li>Name:</li>
<li> Date of Birth:</li>
<li> Language:</li>
</ul>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
what i have tried using so far is
<xsl:value-of select="concat('<',name(parent::*),'> ',.,'
')"/>
but this will print out all the info between the tags
I would like the the output to be like
Name: Hara ali
Date of Birth: 8/23
Language: English
How can I do this with xslt?
Thank you!
Upvotes: 1
Views: 1218
Reputation: 4033
The text from a node can be received by using xsl:value-of
, you will want to select the fields by their label, something like:
<xsl:value-of select=".//field[@label='First Name']/value" />
You should be able to get the rest by yourself.
Upvotes: 2