Monday 2 December 2013

Accessing network drives in XSLT

Issue:

I have an xml document that lists several folders:

<folders>
 <folder>foo1</folder>
 <folder>foo2</folder>
 <folder>foo3</folder>
</folders>

and these need to be used to create three result documents on a shared folder on the network using Saxon 9 as the transformation engine.

Resolution:

Using the simple template:

<xsl:template match="folder">
  <xsl:result-document href="{.}/new.xml" method="xml">
  <new>
   <folder/>
  </new>
  </xsl:result-document>
</xsl:template> 

we can specify the absolute path in the href attribute.

Either

Map the shared folder on the network drive to a local drive letter and use the following:

file:///w:/share/{.}/new.xml

Write directly to the shared folder on the drive (note the four forward slashes)

file:////networkPC1234/share/{.}/new.xml