THIS IS MY xsl after Title I need to display VacancyID from below xml can you any help me how to get this value
unable to access atom-field in xsl
need help to fix this
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>abc</title>
<link>https://google.com</link>
<description>test</description>
<item>
<link>https://google.com</link>
<title>abc</title>
<a10:updated>2016-06-22T10:44:49Z</a10:updated>
<a10:content type="text/xml">
<Vacancy>
<VacancyID>123</VacancyID>
</Vacancy>
</a10:content>
</item>
</channel>
</rss>
xsl:
THIS IS MY xsl after Title i need to display VacancyID from ablove xml can you any help me how to get this valu
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom">
<xsl:output omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
<div id="press-release">
<xsl:apply-templates select="rss/channel/item"/>
</div>
</xsl:template>
<xsl:template match="item">
<div class="press-item">
<a href="{./link}" target="_blank" class="title" title="{./title}">
<xsl:value-of select="./title" disable-output-escaping="yes" />
vacancyID????????????(need heleher)
</a>
<xsl:template match="atom:content">
From within your template matching item, you can use:
<xsl:value-of select="atom:content/Vacancy/VacancyID" />
to get the value of VacancyID.
Related
I am stuck with a XSLT 1.0 problem. I tried to find info on StackOverflow but I couldn't apply the examples.
Here is the structure of my XML:
<XML>
<PR>
<AS>
<ID_AS>AS-001</ID_AS>
<FIRST>
<ID_CATALOG>Id-001</ID_CATALOG>
<STATUS>NOK</STATUS>
</FIRST>
<SECOND>
<ID_CATALOG>Id-002</ID_CATALOG>
<STATUS>OK</STATUS>
</SECOND>
</AS>
<AS>
<ID_AS>AS-002</ID_AS>
<FIRST>
<ID_CATALOG>Id-003</ID_CATALOG>
<STATUS>OK</STATUS>
</FIRST>
<SECOND>
<ID_CATALOG>Id-004</ID_CATALOG>
<STATUS>OK</STATUS>
</SECOND>
</AS>
</PR>
<METADATA>
<ID_CATALOG>Id-001</ID_CATALOG>
<ANGLES>32.25</ANGLES>
</METADATA>
<METADATA>
<ID_CATALOG>Id-002</ID_CATALOG>
<ANGLES>18.75</ANGLES>
</METADATA>
<METADATA>
<ID_CATALOG>Id-003</ID_CATALOG>
<ANGLES>5.23</ANGLES>
</METADATA>
<METADATA>
<ID_CATALOG>Id-004</ID_CATALOG>
<ANGLES>12.41</ANGLES>
</METADATA>
</XML>
I want to display for each AS, the FIRST/ID_CATALOG, FIRST/STATUS and ANGLES corresponding to the ID_CATALOG, then SECOND/etc.
The output would be similar to:
AS-001
Id-001 NOK 32.25
Id-002 OK 18.75
AS-002
Id-003 OK 5.23
Id-004 OK 12.41
I tried the following XSL but I only get the ANGLES for the first item
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns="http://earth.google.com/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:hma="http://earth.esa.int/hma" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>
<!--==================MAIN==================-->
<xsl:template match="/">
<html>
<body>
AS List:
<br/><br/>
<xsl:call-template name="ASandCo"/>
</body>
</html>
</xsl:template>
<!--==================TEMPLATES==================-->
<xsl:template name="ASandCo">
<AS>
<xsl:for-each select="XML/PR/AS">
<xsl:value-of select="ID_AS"/>
<br/>
<xsl:value-of select="FIRST/ID_CATALOG"/> - <xsl:value-of select="FIRST/STATUS"/> -
<xsl:if test="contains(/XML/METADATA/ID_CATALOG, FIRST/ID_CATALOG)">
<xsl:value-of select="/XML/METADATA/ANGLES"/>
</xsl:if>
<br/>
<xsl:value-of select="SECOND/ID_CATALOG"/> - <xsl:value-of select="SECOND/STATUS"/> -
<xsl:if test="contains(/XML/METADATA/ID_CATALOG, SECOND/ID_CATALOG)">
<xsl:value-of select="/XML/METADATA/ANGLES"/>
</xsl:if>
<br/><br/>
</xsl:for-each>
</AS>
</xsl:template>
</xsl:stylesheet>
This XSLT will be applied to very large XML files, so I am trying to find the most efficient way.
Thank you very much in advance!
It seems like you want to look up some metadata metadata based on the ID_CATALOG value.
An efficient way to do this is by using a key. You can define a key on the top level:
<xsl:key name="metadata-by-id_catalog" match="METADATA" use="ID_CATALOG"/>
And then you can look up the ANGLES value using the key for a given ID_CATALOG value like this:
<xsl:value-of select="key('metadata-by-id_catalog', FIRST/ID_CATALOG)/ANGLES"/>
and this:
<xsl:value-of select="key('metadata-by-id_catalog', SECOND/ID_CATALOG)/ANGLES"/>
I have a rss xml file that looks like below with the tag looping many times. I would like to replace the letter 's' with 'm' in the url inside the tag, So http://farm4.staticflickr.com/3802/9593294742_a38fca47c7_s.jpg becomes http://farm4.staticflickr.com/3802/9593294742_a38fca47c7_m.jpg
<rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:creativeCommons="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html" xmlns:flickr="urn:flickr:user" version="2.0">
<channel>
<title>CCGalleria Pool</title>
<link>http://www.flickr.com/groups/ccgalleria/pool/</link>
<item>
<title>Hampton Court Palace Gardens</title>
<link>http://www.flickr.com/photos/dksesh/9593294742/in/pool-1540822#N20</link>
<description>
<p>
dksesh
has added a photo to the pool:</p>
<p>
<a href="http://www.flickr.com/photos/dksesh/9593294742/" title="Hampton Court Palace Gardens">
<img src="http://farm4.staticflickr.com/3802/9593294742_a38fca47c7_m.jpg" width="240" height="107" alt="Hampton Court Palace Gardens"/>
</a>
</p>
</description>
<pubDate>Sun, 25 Aug 2013 10:33:09 -0700</pubDate>
<dc:date.Taken>2013-08-10T16:49:05-08:00</dc:date.Taken>
<author flickr:profile="http://www.flickr.com/people/dksesh/">nobody#flickr.com (dksesh)</author>
<guid isPermaLink="false">tag:flickr.com,2004:/grouppool/1540822#N20/photo/9593294742</guid>
<media:content url="http://farm4.staticflickr.com/3802/9593294742_a38fca47c7_b.jpg" type="image/jpeg" height="456" width="1024"/>
<media:title>Hampton Court Palace Gardens</media:title>
<media:thumbnail url="http://farm4.staticflickr.com/3802/9593294742_a38fca47c7_s.jpg" HEIGHT="75" WIDTH="75"/>
<media:credit ROLE="photographer">dksesh</media:credit>
<creativeCommons:license>http://creativecommons.org/licenses/by-nd/2.0/deed.en_GB</creativeCommons:license>
</item>
</channel>
</rss>
I have a code something like below, but didn't work. Can someone help? Thanks very much. Newly changed code below.
<?xml version='1.0'?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:media="http://search.yahoo.com/mrss/">
<xsl:output method="html" />
<xsl:template match="/">
<xsl:for-each select="rss/channel/item">
<xsl:variable name="newurl" select="replace(media:thumbnail/#url,'_s.jpg','_m.jpg')"/>
<img src="{$newurl}" style="margin:5px 5px" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Your stylesheet sample showns the version as "2.0" which is good, because there is a replace function you can use in XSLT 2.0 that will probably do the trick here
<xsl:variable name="newurl" select="replace(media:thumbnail/#url,'_s.jpg','_m.jpg')"/>
<img src="{$newurl}" style="margin:5px 5px" />
Note that the second argument of the replace function can actually be a regular expression, if you wanted more control over what 's' needed to be replaced.
As an aside, do note the correct use of Attribute Value Templates here, signified by the curly braces { }. You use them in outputting the src attribute of the img element, but not within the translate/replace function.
Here is the full XSLT in this case:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:media="http://search.yahoo.com/mrss/">
<xsl:output method="html" />
<xsl:template match="/">
<xsl:for-each select="rss/channel/item">
<xsl:variable name="newurl" select="replace(media:thumbnail/#url,'_s.jpg','_m.jpg')"/>
<img src="{$newurl}" style="margin:5px 5px" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I have the following XML
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="sample.xsl" type="text/xsl"?>
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel
xmlns:cfi="http://www.microsoft.com/schemas/rss/core/2005/internal">
<title cf:type="text">The Hindu - Front Page</title>
<link>http://www.hindu.com/</link>
<description cf:type="text">The Internet edition of The Hindu,
India's national newspaper</description>
<image>
<url>http://www.hindu.com/hindu/hindux.gif</url>
<title>hindu.com</title>
<link>http://www.hindu.com/</link>
</image>
<item>
<title cf:type="text"
xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005"
>ISRO spectrum deal under review: Centre</title>
</item>
<item>
<title cf:type="text"
xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005"
>Response from Devas</title>
</item>
</channel>
</rss>
The rss/channel/item can be of any count(in the current case it's count is 2). I need to display the Titles as a Marquee one after the other as follows
ISRO spectrum deal under review: Centre, Response from Devas,....,....
How can I accomplish this in XSLT? kindly advice
Thanks
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cfi="http://www.microsoft.com/schemas/rss/core/2005/internal"
xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005"
xmlns:dc="http://purl.org/dc/elements/1.1/"
exclude-result-prefixes="cfi cf dc">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/*">
<div id="marquee">
<xsl:apply-templates select="channel/item/title"/>
</div>
</xsl:template>
<xsl:template match="title">
<xsl:value-of select="."/>
<xsl:if test="not(position() = last())">, </xsl:if>
</xsl:template>
</xsl:stylesheet>
Result against your sample:
<div id="marquee">ISRO spectrum deal under review: Centre, Response from Devas</div>
In addition to #Flack correct answer, in XSLT 2.0 xsl:value-of instruction preserves sequence. So, this stylesheet:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<div id="marquee">
<xsl:value-of select="rss/channel/item/title"
separator=", "/>
</div>
</xsl:template>
</xsl:stylesheet>
Also outputs:
<div id="marquee"
>ISRO spectrum deal under review: Centre, Response from Devas</div>
I have the following XML
<?xml version="1.0" encoding="ISO-8859-1" ?>
- <DEVICEMESSAGES>
<VERSION xml="1" checksum="" revision="0" envision="33050000" device="" />
<HEADER id1="0001" id2="0001" content="Nasher[<messageid>]: <!payload>" />
<MESSAGE level="7" parse="1" parsedefvalue="1" tableid="15" id1="24682" id2="24682" eventcategory="1003010000" content="Access to <webpage> was blocked due to its category (<info> by <hostname>)" />
</DEVICEMESSAGES>
I am using the following xslt
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="DEVICEMESSAGES">
<xsl:value-of select="#id2"/>,<xsl:text/>
<xsl:value-of select="#content"/>,<xsl:text/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
when i use MSXML i just get ,, whereas i want to have something like
id2, content
0001 , Nasher[<messageid>]: <!payload>"
The DEVICEMESSAGES element doesn't have attributes at all.
Change:
<xsl:template match="DEVICEMESSAGES">
to:
<xsl:template match="DEVICEMESSAGES/HEADER">
Here is a snip-it of the XML:
<?xml version="1.0" encoding="iso-8859-1" ?>
<NetworkAppliance id="S123456">
<Group id="9">
<Probe id="1">
<Value>74.7</Value>
</Probe>
</NetworkAppliance>
I want to get the single point value of 74.7. There are many groups with unique ID's and many Probes under that group with unique ID's each with values.
I am looking for example XSLT code that can get me this one value. Here is what i have that does not work:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" version="3.2" />
<xsl:template match="NetworkAppliance">
<xsl:apply-templates select="Group[#id='9']"/>
</xsl:template>
<xsl:template match="Group">
Temp: <xsl:value-of select="Probe[#id='1']/Value"/>
<br/>
</xsl:template>
</xsl:stylesheet>
Here is what worked for me in the end:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="NetworkAppliance/Group[#id=9]/Probe[#id=1]">
Value: <xsl:value-of select="Value" />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Don't forget that you can do select several levels at once. Fixing your XML to:
<?xml version="1.0" encoding="iso-8859-1" ?>
<NetworkAppliance id="S123456">
<Group id="9">
<Probe id="1">
<Value>74.7</Value>
</Probe>
</Group>
</NetworkAppliance>
and using this stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" version="3.2" />
<xsl:template match="/">
Temp: <xsl:value-of select="//Group[#id='9']/Probe[#id='1']/Value"/>
<br/>
</xsl:template>
</xsl:stylesheet>
we can pick out that one item you're interested in.
Points to note:
The // part of the expression means that the search for Group nodes takes place throughout the whole tree, finding Group nodes at whatever depth they're at.
The [#id='9'] part selects those Group nodes with id of 9
The Probe[#id='1'] part immediately after that selects those children of the Group nodes it found where the id is 1, and so on.
<xsl:value-of select="/NetworkAppliance/Group[#id=9]/Probe[#id=1]/Value"/>
XSLT is just one of the tools in the box, and nothing without XPath.
the xpath for value of a node is /node/text()
So
<xsl:value-of select="Probe[#id='1']/text()"/>