Useful for:

  • Pulling an document from another location and including data from it into another location
  • Extracting a list of all the names of paragraph styles in a project
  • Extracting all the asset names used by a particular project (not just the list of the assets in the entire job jacket), in order to populate a pop-up menu in a web front end to QuarkXPress Server
  • Extracting the most important information for a project or publication from a job jacket

Procedure:
To extract information from a Job Jacket, execute the XSLT procedures described below.

The Document Method: To pull an document from another location and include data from it into another location, run an XSLT similar to this:

<xsl:stylesheet ns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:template match='/'>
<xsl:variable name='jj'>http://localhost:8080/literal/<xsl:value-of select='PROJECT/@JOBJACKET'/></xsl:variable>
<xsl:copy-of select='document($jj)'/>
</xsl:template>
</xsl:stylesheet>

Once you have run it save it into the docpool as “getJJ.xsl” and then call it with the URL:

http://server:port/documentname.?jjname=documentnameJJ.&XSL=getJJ.xsl

The document() method can also be incorporated as part of an XPath. Suppose you want to get a list names of paragraph styles, you can use XSLT to do so in the following manner:

<xsl:stylesheet ns:xsl='http://www.w3.org/1999/XSL/Transform' ns:JDF='http://www.CIP4.org/JDFSchema_1_1' ns:qxp='http://www.quark.com/QuarkXPress/JDF_1' version='1.0'>
<xsl:template match='/'>
<xsl:variable name='jj'>http://localhost:8080/literal/<xsl:value-of select='PROJECT/@JOBJACKET'/></xsl:variable>
<xsl:for-each select='document($jj)//qxp:ParaStyle'>
<xsl:element name='Parastyle'><xsl:value-of select='./@Name'/></xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

To extract all the asset names used by a particular project:

<? version='1.0' encoding='UTF-8'?>
<xsl:stylesheet ns:xsl='http://www.w3.org/1999/XSL/Transform'
ns:JDF='http://www.CIP4.org/JDFSchema_1_1' ns:qxp='http://www.quark.com/QuarkXPress/JDF_1'
version='1.0'>
<xsl:variable
name='jj'>http://localhost:8080/literal/<xsl:value-of select='PROJECT/@JOBJACKET'/></xsl:variable>
<xsl:variable
name='ticket'><xsl:value-of select='PROJECT/@JOBTICKET'/></xsl:variable>
<xsl:template
match='/'>
<xsl:element
name='assets'>
<xsl:for-each
select='document($jj)//qxp:ParaStyle[@ID=//JDF:JDF[@Name=$ticket]//qxp:ParaStyleLink/@rRef]'>
<xsl:element
name='ParaStyle'>
<xsl:value-of
select='./@Name'/>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

More Information:
All this XSLT is doing is “get me every qxp:ParaStyle, in the document at
http://localhost:8080/literal/<jobjacketname>. <http://localhost:8080/literal/%3cjobjacketname%3e.> , where the ID of that Parastyle (which will be in the global resource pool inside the job jacket) is also referenced as a “qxp:ParaStyleLink” inside the JDF element. The JDF element name is the same as the name of the Job Ticket which I know from my modifier (i.e. the JDF element which relates to this project)”. Note how you can nest the conditions on the XPath, this is a useful functionality that allows you to write some complex logic in a very compact form. Please see the XSLT files attached to this solution for additional XSLT methods and techniques.

Additional Notes:
How would you use this practically? Suppose you had a QPS Script that, for some reason, needed to know all the colors available in a project to ensure it didn’t send an invalid color name in a Modifier request. You could start with the script below (N.B. assumes the XSLT listed above is saved as “projectinfo.xsl” in the docpool):

importPackage(Packages.org..sax);
importPackage(Packages.javax..parsers);
importPackage(Packages.javax..xpath);
load ('QpsFunctions');

var ctx = new QRequestContext();
ctx.setDocumentName('Helloworld.qxp');
ctx.setResponseAsURL(true);
var Req = new Request();
Req.setJobJacketPath('helloworldJJ.');
Req.setXSL('file:projectinfo.xsl');
ctx.setRequest(Req);
var response = s_sdkEngine.processRequest(ctx);
print('http://localhost:61400/' response.getResponseURL());
var Doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource('http://localhost:61400' response.getResponseURL()));
var xpath = XPathFactory.newInstance().newXPath().compile('//Color/text()');
var result = xpath.evaluate(Doc, XPathConstants.NODESET);
for (var x = 0; x < result.getLength(); x) {
print(result.item(x).getNodeValue());
}

In this case, the script simply prints all the color names to the console.

Note: XPath here is being used to easily locate a particular set of elements in the , in this case the “Color” elements.

As an additional example, suppose you wanted to build a website that got information about all the available assets in a project and present them for the user to choose, perhaps the color, and paragraph / character styles for a box, you’d could do that with an (ugly) PHP page something like this:

<?php
$= simple_load_file('http://localhost:8080//helloworld.qxp?jjname=helloworldJJ.&XSL=file:projectinfo.xsl');
echo '<html><body><form>Color: <select name='color'>';
foreach($->xpath('//Color') as $node)
{
echo '<option value=' . $node . '>' . $node . '</option>';
}
echo '</select><br>';
echo 'Paragraph Style: <select name='parastyle'>';
foreach($->xpath('//ParagraphStyle') as $node) {
echo '<option value=' . $node . '>' . $node . '</option>';
}
echo '</select><br>';
echo 'Character Style: <select name='charstyle'>';
foreach($->xpath('//CharacterStyle') as $node) {
echo '<option value=' . $node . '>' . $node . '</option>';
}
echo '</select><br>';
echo '</form></body></html>';
?>