Solved

Getting attribute Values using xslt

Posted on 2016-09-02
4
34 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now