Solved

Getting attribute Values using xslt

Posted on 2016-09-02
4
46 Views
Last Modified: 2016-09-08
Hi All,

I am trying to get the attribute value from 100's of xml files using below code..
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	version="2.0" xmlns:saxon="http://sf.net/saxon" xmlns:xs="http://www.w3.org/2001/XMLSchema"
	exclude-result-prefixes="saxon xs">
	<xsl:output indent="yes" method="html" encoding="UTF-8" />
	<xsl:strip-space elements="*" />
	<xsl:template match="/">
		<html>
			<body>
				<ol>
					<xsl:for-each select="//fileref/@href">
						<xsl:variable name="file" select="concat('../input.files/',.)" />
						<xsl:message>Processing ...<xsl:value-of select="." /></xsl:message>
						<xsl:for-each select="document($file)/distinct-values(//trans-unit/@id)">
							<xsl:sort order="ascending" select="." />
							<li>
								<xsl:value-of select="." />
							</li>
						</xsl:for-each>
					</xsl:for-each>
				</ol>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>

Open in new window

However, I am not getting any results.

Can you please suggest what's gone wrong here?
Thanks,
Shail
0
Comment
Question by:Shailesh Shinde
  • 2
  • 2
4 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 41781474
technically I don't see a direct issue
but it is very hard to comment on this... and it is really easy for you to debug

1. first test the outer loop
				<ol>
					<xsl:for-each select="//fileref/@href">
						<xsl:variable name="file" select="concat('../input.files/',.)" />
							<li>
								<xsl:value-of select="$file" />
							</li>
						</xsl:for-each>
					</xsl:for-each>
				</ol>

Open in new window


So then you know whether the source XML file already gives you the correct file urls
(you have not added the source XML so I can't test that myself)
0
 
LVL 3

Author Comment

by:Shailesh Shinde
ID: 41781518
Hi Geert,

Yes, I did that and when I changed the xpath something like below it has shown the results.
<xsl:for-each select="document($file)/distinct-values(//@id)">

Open in new window

This is strange as xml structure is quite simple...
<file>
<body>
<group>
<trans-unit id="m1"></trans-unit>
<trans-unit id="m1"></trans-unit>
<trans-unit id="m2"></trans-unit>
<trans-unit id="m2"></trans-unit>
</group>
</body>
</file>

Open in new window

Thanks,
Shail
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 41781544
so... you are proving you question was not detailed enough
Please, in future give ALL information, because only now it is apparent what you should be looking at

if this is working
            <xsl:for-each select="document($file)/distinct-values(//@id)">
                        
and this is not
            <xsl:for-each select="document($file)/distinct-values(//trans-unit/@id)">

it simply means that there are no @id in a <trans-unit> element
I am pretty certain that the XML example you show is not complete
I bet there is an xml namespace declaration binding the default namespace to a namespace different from the NULL namespace

I assume this would work
            <xsl:for-each select="document($file)/distinct-values(//*:trans-unit/@id)">
0
 
LVL 3

Author Closing Comment

by:Shailesh Shinde
ID: 41789351
Yes, this works perfectly
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
WCAG audit tools 1 81
SP to delete duplicates 15 70
Test ddwrt:UserLookup 1 64
XML Data Missing in PHP SimpleXML 8 61
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question