Avatar of Shailesh Shinde
Shailesh Shinde
Flag for India asked on

Getting attribute Values using xslt

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
Web Languages and StandardsXML

Avatar of undefined
Last Comment
Shailesh Shinde

8/22/2022 - Mon
Gertone (Geert Bormans)

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)
Shailesh Shinde

ASKER
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
ASKER CERTIFIED SOLUTION
Gertone (Geert Bormans)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Shailesh Shinde

ASKER
Yes, this works perfectly
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck