[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: collection is not working
also wanted to say, I used Saxon-HE due to my convenience. Saxon-PE or Saxon-EE are better to be used in a professional project. Or for that matter Schema Aware XSLT processors from other vendors. That allows us to use more strongly typed (among other benefits) XSLT language. On Tue, Apr 3, 2018 at 2:50 PM, Mukul Gandhi gandhi.mukul@xxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Hi Rahul, > Here's something that I tried, which worked. > > The XSLT stylesheet is, > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > > xmlns:xsi="http://www.w3.org/ > 2001/XMLSchema-instance" > exclude-result-prefixes="xsi" > version="2.0"> > > <xsl:output method="text"/> > <xsl:param name="DocumentsURI" /> > > <xsl:template match="/"> > <xsl:text>Filename Schema name
</xsl:text> > <xsl:for-each select="collection(concat($ > DocumentsURI,'?select=*.xml;recurse=yes;on-error=ignore'))"> > <xsl:variable name="fileName" select="base-uri()"/> > <xsl:variable name="schemaName" select="article/@xsi: > noNamespaceSchemaLocation"/> > <xsl:value-of select="tokenize($fileName,'/')[last()]"/> > <xsl:text> </xsl:text> > <xsl:value-of select="$schemaName"/> > <xsl:text>
</xsl:text> > </xsl:for-each> > </xsl:template> > > </xsl:stylesheet> > > Please create a parameter to stylesheet as follows, > name: DocumentsURI > value: file:/C:/Users/mukul/Desktop/test > (the 'value' is where, all my XML files and XSLT are kept. Please mention > location as per your local environment) > > I specified the XML files as follows, > aa.xml > <?xml version="1.0" encoding="UTF-8"?> > <article xsi:noNamespaceSchemaLocation="aa.xsd" xmlns:xsi=" > http://www.w3.org/2001/XMLSchema-instance"> > <name>aaas</name> > </article> > > Similarly for other XML files. > > After running the stylesheet I get following output, > Filename Schema name > aa.xml aa.xsd > bb.xml bb.xsd > cc.xml cc.xsd > > I used Saxon-HE 9.7.0.19, to test this. > > Hope this helps. > > On Mon, Apr 2, 2018 at 10:09 PM, Rahul Singh rahulsinghindia15@xxxxxxxxx < > xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > >> Hi, >> >> I have 100 xml file which contains xml data with schemalocation namespace >> in root element, i have written xslt to merge file name with schema name in >> one file but i am not able to generate my output : >> >> *Input: * >> *aa.xml* >> <?xml version="1.0" encoding="UTF-8"?> >> *<article xsi:noSchemaLocation="aa.xsd">* >> <name>aaas</name> >> </article> >> >> >> *bb.xml* >> <?xml version="1.0" encoding="UTF-8"?> >> *<article xsi:noSchemaLocation="bb.xsd">* >> <name>ars</name> >> </article> >> >> >> *cc.xml* >> <?xml version="1.0" encoding="UTF-8"?> >> *<article> xsi:noSchemaLocation="cc.xsd"* >> <name>tytu</name> >> </article> >> >> >> *Expected output:* >> >> Filename Schema name >> aa.xml aa.xsd >> bb.xml bb.xsd >> cc.xml cc.xsd >> >> >> *code:* >> >> <?xml version="1.0" encoding="UTF-8"?> >> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1 >> 999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" >> xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn=" >> http://www.w3.org/2005/xpath-functions"> >> <xsl:output method="xml" indent="yes"/> >> <xsl:strip-space elements="*"/> >> <xsl:param name="DocumentsURI" select="'file:/C:/Users/rahul/ >> Downloads/ARB/ARB'"/> >> <xsl:template match="node()|@*"> >> <xsl:copy> >> <xsl:apply-templates select="node()|@*"/> >> </xsl:copy> >> </xsl:template> >> <xsl:template match="/"> >> <!--Generating Result Docuemnt--> >> <xsl:result-document href="Merged.xml" method="xml" indent="yes"> >> <Articles> >> <xsl:for-each select="collection(concat($Doc >> umentsURI,'?select=*.xml;recurse=yes;on-error=ignore'))"> >> <xsl:apply-templates select="/article"/> >> </xsl:for-each> >> </Articles> >> </xsl:result-document> >> </xsl:template> >> </xsl:stylesheet> >> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> >> EasyUnsubscribe <http://-list/2709226> (by email) >> > > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <-list/2709226> (by > email <>) > -- Regards, Mukul Gandhi
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|