ffranziiska
ffranziiska

Reputation: 37

XSLT Transformation within bash pass XPATH value to output file name

I am doing a batch xsl transformation and want to use a parameter from my stylesheet to form the outputfile name, but I am rather unsure how to do that, it should be something like:

$output = Join-Path $mypath {{XPATH}} $file.Name
java -cp $saxonpath net.sf.saxon.Transform -t -s:$file -xsl:$xsltpath -o:$output

(with {{XPATH}} referring to my XPATH, something simple as count(//error))

Hope someone can help me with that.z Thanks!

Upvotes: 0

Views: 166

Answers (2)

Martin Honnen
Martin Honnen

Reputation: 167716

If you want to do XPath evaluation before running the XSLT to compute e.g. that count then call the XQuery processor with e.g.

java -cp $saxonpath net.sf.saxon.Query -qs:'count(//error)' -s:$file '!method=text'

e.g. to store that in a variable

count=`java -cp $saxonpath net.sf.saxon.Query -qs:'count(//*)' -s:$file '!method=text'`

or, in your original version, probably

$output = Join-Path $mypath `java -cp $saxonpath net.sf.saxon.Query -qs:'count(//*)' -s:$file '!method=text'` $file.Name

Upvotes: 0

Sebastien
Sebastien

Reputation: 2714

Instead of defining an output with -o:$output You could pass your output path as a parameter to your tranformation and use xsl:result-document to create your output file.

Something along those lines :

$output = Join-Path $mypath $file.Name
java -cp $saxonpath net.sf.saxon.Transform -t -s:$file -xsl:$xsltpath -mypath=$output

<xsl:stylesheet>
  ...
  <xsl:param name="mypath"/>
  ...
  <xsl:result-document href="concat($mypath,count(//error))" method="xml">
    ...
  </xsl:result-document>
</xsl:stylesheet>

Depending on your system you need to be cautious of the separator used in your path.

Upvotes: 2

Related Questions