Page 1 of 1

get value of different grandchild of ancestor

Posted: Mon Jan 18, 2010 7:57 pm
by metalhammer
Hi,

I have an xml file which contains (xmp)metadata of an PDF file for printing.

In the xml file there is a list with all used inks.
There is also is a port which says for each page what inks are used, but does not say the name of the ink but its sequence number in the ink list.

I would like to have a list with the names of the used inks for each page.
Something like this:

Inks used from page 1 to page 1: Process cyan, Process magenta, Process yellow, Process black, Pantone 5404

My xml file:

Code: Select all


<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<?xml-stylesheet type="text/xsl" href="XMP_omvormen.xslt"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.2-c063 53.352624, 2008/07/30-18:05:41 ">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:egGr="http://ns.esko-graphics.com/grinfo/1.0/"
xmlns:egInk="http://ns.esko-graphics.com/inkinfo/1.0/">

<egGr:inks>
<rdf:Seq>
<rdf:li rdf:parseType="Resource">
<egInk:name>5405</egInk:name>
<egInk:type>pantone</egInk:type>
<egInk:frequency>150.</egInk:frequency>
<egInk:angle>22.5</egInk:angle>
<egInk:dotshape>R</egInk:dotshape>
<egInk:r>.3218039274</egInk:r>
<egInk:g>.4258823395</egInk:g>
<egInk:b>.4894117713</egInk:b>
<egInk:attribute>normal</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>583</egInk:name>
<egInk:type>pantone</egInk:type>
<egInk:frequency>150.</egInk:frequency>
<egInk:angle>82.5</egInk:angle>
<egInk:dotshape>R</egInk:dotshape>
<egInk:r>.6988235116</egInk:r>
<egInk:g>.7109804153</egInk:g>
<egInk:b>0.</egInk:b>
<egInk:attribute>normal</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>cyan</egInk:name>
<egInk:type>process</egInk:type>
<egInk:frequency>150.</egInk:frequency>
<egInk:angle>15.</egInk:angle>
<egInk:dotshape>C</egInk:dotshape>
<egInk:r>0.</egInk:r>
<egInk:g>.5843137503</egInk:g>
<egInk:b>.8862745166</egInk:b>
<egInk:attribute>normal</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>yellow</egInk:name>
<egInk:type>process</egInk:type>
<egInk:frequency>150.</egInk:frequency>
<egInk:angle>90.</egInk:angle>
<egInk:dotshape>C</egInk:dotshape>
<egInk:r>1.</egInk:r>
<egInk:g>.9725490212</egInk:g>
<egInk:b>0.</egInk:b>
<egInk:attribute>normal</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>black</egInk:name>
<egInk:type>process</egInk:type>
<egInk:frequency>150.</egInk:frequency>
<egInk:angle>45.</egInk:angle>
<egInk:dotshape>C</egInk:dotshape>
<egInk:r>.1960784346</egInk:r>
<egInk:g>.1960784346</egInk:g>
<egInk:b>.2078431398</egInk:b>
<egInk:attribute>normal</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>magenta</egInk:name>
<egInk:type>process</egInk:type>
<egInk:frequency>150.</egInk:frequency>
<egInk:angle>75.</egInk:angle>
<egInk:dotshape>C</egInk:dotshape>
<egInk:r>.8313725591</egInk:r>
<egInk:g>0.</egInk:g>
<egInk:b>.4823529422</egInk:b>
<egInk:attribute>normal</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>black</egInk:name>
<egInk:type>process</egInk:type>
<egInk:frequency>133.</egInk:frequency>
<egInk:angle>45.</egInk:angle>
<egInk:dotshape>C</egInk:dotshape>
<egInk:r>.1960784346</egInk:r>
<egInk:g>.1960784346</egInk:g>
<egInk:b>.2078431398</egInk:b>
<egInk:attribute>normal</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>marron</egInk:name>
<egInk:type>designer</egInk:type>
<egInk:frequency>120.</egInk:frequency>
<egInk:angle>45.</egInk:angle>
<egInk:dotshape>R</egInk:dotshape>
<egInk:r>.6745098233</egInk:r>
<egInk:g>.4313725531</egInk:g>
<egInk:b>.160784319</egInk:b>
<egInk:attribute>normal</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>395</egInk:name>
<egInk:type>pantone</egInk:type>
<egInk:frequency>120.</egInk:frequency>
<egInk:angle>52.5</egInk:angle>
<egInk:dotshape>R</egInk:dotshape>
<egInk:r>.9188235402</egInk:r>
<egInk:g>.8870587945</egInk:g>
<egInk:b>0.</egInk:b>
<egInk:attribute>normal</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>8281</egInk:name>
<egInk:type>pantone</egInk:type>
<egInk:frequency>120.</egInk:frequency>
<egInk:angle>7.5</egInk:angle>
<egInk:dotshape>R</egInk:dotshape>
<egInk:r>.4815686345</egInk:r>
<egInk:g>.5549019575</egInk:g>
<egInk:b>.5101960897</egInk:b>
<egInk:attribute>opaque</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>stef</egInk:name>
<egInk:type>designer</egInk:type>
<egInk:frequency>120.</egInk:frequency>
<egInk:angle>52.5</egInk:angle>
<egInk:dotshape>R</egInk:dotshape>
<egInk:r>.2078431398</egInk:r>
<egInk:g>.5098039508</egInk:g>
<egInk:b>.6666666865</egInk:b>
<egInk:attribute>normal</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>Artios Cut</egInk:name>
<egInk:type>designer</egInk:type>
<egInk:frequency>120.</egInk:frequency>
<egInk:angle>45.</egInk:angle>
<egInk:dotshape/>
<egInk:r>.1960784346</egInk:r>
<egInk:g>.1960784346</egInk:g>
<egInk:b>.2078431398</egInk:b>
<egInk:attribute>technical</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>Artios Crease</egInk:name>
<egInk:type>designer</egInk:type>
<egInk:frequency>120.</egInk:frequency>
<egInk:angle>45.</egInk:angle>
<egInk:dotshape/>
<egInk:r>.9482352734</egInk:r>
<egInk:g>0.</egInk:g>
<egInk:b>.1169019639</egInk:b>
<egInk:attribute>technical</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>keyline</egInk:name>
<egInk:type>designer</egInk:type>
<egInk:frequency>120.</egInk:frequency>
<egInk:angle>45.</egInk:angle>
<egInk:dotshape/>
<egInk:r>.4945098162</egInk:r>
<egInk:g>.8823529482</egInk:g>
<egInk:b>.186823532</egInk:b>
<egInk:attribute>technical</egInk:attribute>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egInk:name>vernis</egInk:name>
<egInk:type>designer</egInk:type>
<egInk:frequency>120.</egInk:frequency>
<egInk:angle>45.</egInk:angle>
<egInk:dotshape/>
<egInk:r>.9843137264</egInk:r>
<egInk:g>.9137254953</egInk:g>
<egInk:b>.8431372643</egInk:b>
<egInk:attribute>varnish</egInk:attribute>
</rdf:li>
</rdf:Seq>
</egGr:inks>
</rdf:Description>

<rdf:Description rdf:about=""
xmlns:egPagL="http://ns.esko-graphics.com/pagerangelist/1.0/"
xmlns:egPag="http://ns.esko-graphics.com/pagerange/1.1/">
<egPagL:pagelist>
<rdf:Seq>
<rdf:li rdf:parseType="Resource">
<egPag:start>0</egPag:start>
<egPag:end>0</egPag:end>
<egPag:inks>
<rdf:Seq>
<rdf:li>1</rdf:li>
<rdf:li>2</rdf:li>
<rdf:li>3</rdf:li>
<rdf:li>4</rdf:li>
<rdf:li>5</rdf:li>
<rdf:li>6</rdf:li>
<rdf:li>8</rdf:li>
<rdf:li>9</rdf:li>
<rdf:li>12</rdf:li>
<rdf:li>13</rdf:li>
</rdf:Seq>
</egPag:inks>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egPag:start>1</egPag:start>
<egPag:end>1</egPag:end>
<egPag:inks>
<rdf:Seq>
<rdf:li>1</rdf:li>
<rdf:li>2</rdf:li>
<rdf:li>3</rdf:li>
<rdf:li>4</rdf:li>
<rdf:li>5</rdf:li>
<rdf:li>6</rdf:li>
<rdf:li>8</rdf:li>
<rdf:li>9</rdf:li>
</rdf:Seq>
</egPag:inks>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egPag:start>2</egPag:start>
<egPag:end>2</egPag:end>
<egPag:inks>
<rdf:Seq>
<rdf:li>2</rdf:li>
<rdf:li>3</rdf:li>
<rdf:li>4</rdf:li>
<rdf:li>5</rdf:li>
<rdf:li>6</rdf:li>
<rdf:li>8</rdf:li>
<rdf:li>9</rdf:li>
<rdf:li>10</rdf:li>
<rdf:li>11</rdf:li>
<rdf:li>14</rdf:li>
</rdf:Seq>
</egPag:inks>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<egPag:start>3</egPag:start>
<egPag:end>3</egPag:end>
<egPag:inks>
<rdf:Seq>
<rdf:li>1</rdf:li>
<rdf:li>2</rdf:li>
<rdf:li>3</rdf:li>
<rdf:li>4</rdf:li>
<rdf:li>5</rdf:li>
<rdf:li>6</rdf:li>
<rdf:li>7</rdf:li>
<rdf:li>8</rdf:li>
<rdf:li>9</rdf:li>
<rdf:li>15</rdf:li>
</rdf:Seq>
</egPag:inks>
</rdf:li>
</rdf:Seq>
</egPagL:pagelist>
</rdf:Description>

</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
I've tried to do it, but my code doesn't work. (last template, I added my template for the ink list to to make the contents of the file more understandable)
My xslt file:

Code: Select all


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:egInk="http://ns.esko-graphics.com/inkinfo/1.0/"
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
xmlns:egbarc="http://ns.esko-graphics.com/barcode/1.0/"
xmlns:x="adobe:ns:meta/"
xmlns:egextfl2="http://ns.esko-graphics.com/extfileslist/2.0/"
xmlns:egCadReg="http://ns.esko-graphics.com/cadreg/1.0/"
xmlns:egextfl="http://ns.esko-graphics.com/extfileslist/1.0/"
xmlns:eginkcovl="http://ns.esko-graphics.com/inkcovlist/1.0/"
xmlns:xmpmm="http://ns.adobe.com/xap/1.0/mm/"
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
xmlns:egPDFNat="http://ns.esko-graphics.com/pdfnatversion/1.0/"
xmlns:egextf="http://ns.esko-graphics.com/extfile/1.0/"
xmlns:egCadL="http://ns.esko-graphics.com/cadlist/1.0/"
xmlns:xmprights="http://ns.adobe.com/xap/1.0/rights/"
xmlns:egPagL="http://ns.esko-graphics.com/pagerangelist/1.0/"
xmlns:egbarcl="http://ns.esko-graphics.com/barcodelist/1.0/"
xmlns:egGr="http://ns.esko-graphics.com/grinfo/1.0/"
xmlns:xmpbj="http://ns.adobe.com/xap/1.0/bj/"
xmlns:egfontl="http://ns.esko-graphics.com/fontlist/1.0/"
xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:egfont="http://ns.esko-graphics.com/fontinfo/1.0/"
xmlns:egPag="http://ns.esko-graphics.com/pagerange/1.1/"
xmlns:dc="http://purl.org/dc/elements/1.1/"

xmlns:date="http://exslt.org/dates-and-times"
xmlns:str="http://exslt.org/strings">

<xsl:import href="date.format-date.template.xsl"/>


<xsl:template match="rdf:RDF">
<html>
<head>
<title>
XMP data voor: <xsl:value-of select="rdf:Description[namespace::*[.='http://purl.org/dc/elements/1.1/']]/dc:title/rdf:Alt/rdf:li"/>
</title>
<style type="text/css">

body {
font-family:Verdana;
font-size:12pt;
padding:0px;
margin:0px;
margin-left:5px;

border:none;
}
h1 {
font-size:16pt;
}
h3 {
font-size:14pt;
margin-top:15px;
margin-bottom:5px;
}
h5 {
font-size:12pt;
margin-top:15px;
margin-bottom:5px;
}
.kleurvak {
position: relative;
top:0px;
left:0px;
height: 15px;
width: 15px;
border: 1px solid black;
margin:2px;
}
#versie-info {
color:#AAAAAA;
font-size: 8pt;
}

</style>
</head>
<body>
XMP data voor: <br/><h1><xsl:value-of select="rdf:Description[namespace::*[.='http://purl.org/dc/elements/1.1/']]/dc:title/rdf:Alt/rdf:li"/></h1>



<xsl:apply-templates select="rdf:Description[
namespace::*[.='http://ns.esko-graphics.com/grinfo/1.0/'] and
namespace::*[.='http://ns.esko-graphics.com/inkinfo/1.0/']
]" />
<xsl:apply-templates select="rdf:Description[
namespace::*[.='http://ns.esko-graphics.com/pagerangelist/1.0/'] and
namespace::*[.='http://ns.esko-graphics.com/pagerange/1.1/']
]" />


</body>
</html>
</xsl:template>






<!-- esko arwork xmp definition: Graphics p14 -->
<xsl:template match="rdf:Description[
namespace::*[.='http://ns.esko-graphics.com/grinfo/1.0/'] and
namespace::*[.='http://ns.esko-graphics.com/inkinfo/1.0/']
]">

<h5>Gebruikte inkten:</h5>
<!-- eerst process inkt -->
<xsl:for-each select="/x:xmpmeta/rdf:RDF/rdf:Description/egGr:inks/rdf:Seq/rdf:li[egInk:type='process']">
<xsl:sort select="egInk:type"/>

<div class="kleurvak" style="background-color:rgb({round(egInk:r*256)},{round(egInk:g*256)},{round(egInk:b*256)});"/>


<b>Process <xsl:value-of select="egInk:name"/><br/></b>

Lineatuur: <xsl:value-of select="round(egInk:frequency)"/> lpi<br/>
Drukhoek: <xsl:value-of select="round(egInk:angle)"/>°<br/>
? Puntvorm: <xsl:value-of select="egInk:dotshape"/><br/>
R:<xsl:value-of select="round(egInk:r*256)"/> G:<xsl:value-of select="round(egInk:g*256)"/> B:<xsl:value-of select="round(egInk:b*256)"/><br/>
? Soort inkt: <xsl:value-of select="egInk:attribute"/><br/>
<br/>

</xsl:for-each>


<!-- dan pantone inkt -->
<xsl:for-each select="/x:xmpmeta/rdf:RDF/rdf:Description/egGr:inks/rdf:Seq/rdf:li[egInk:type='pantone']">
<xsl:sort select="egInk:type"/>
<div class="kleurvak" style="background-color:rgb({round(egInk:r*256)},{round(egInk:g*256)},{round(egInk:b*256)});"/>
<b>Pantone <xsl:value-of select="egInk:name"/><br/></b>

Lineatuur: <xsl:value-of select="round(egInk:frequency)"/> lpi<br/>
Drukhoek: <xsl:value-of select="round(egInk:angle)"/>°<br/>
? Puntvorm: <xsl:value-of select="egInk:dotshape"/><br/>
R:<xsl:value-of select="round(egInk:r*256)"/> G:<xsl:value-of select="round(egInk:g*256)"/> B:<xsl:value-of select="round(egInk:b*256)"/><br/>
? Soort inkt: <xsl:value-of select="egInk:attribute"/><br/>
<br/>

</xsl:for-each>


<!-- dan eigen inkt-->
<xsl:for-each select="/x:xmpmeta/rdf:RDF/rdf:Description/egGr:inks/rdf:Seq/rdf:li[egInk:type='designer']">
<xsl:sort select="egInk:type"/>
<div class="kleurvak" style="background-color:rgb({round(egInk:r*256)},{round(egInk:g*256)},{round(egInk:b*256)});"/>
<b><xsl:value-of select="egInk:name"/><br/></b>

Lineatuur: <xsl:value-of select="round(egInk:frequency)"/> lpi<br/>
Drukhoek: <xsl:value-of select="round(egInk:angle)"/>°<br/>
? Puntvorm: <xsl:value-of select="egInk:dotshape"/><br/>
R:<xsl:value-of select="round(egInk:r*256)"/> G:<xsl:value-of select="round(egInk:g*256)"/> B:<xsl:value-of select="round(egInk:b*256)"/><br/>
? Soort inkt: <xsl:value-of select="egInk:attribute"/><br/>
<br/>

</xsl:for-each>


<br/>
</xsl:template>


<!-- esko artwork pages p30 -->
<xsl:template match="rdf:Description[
namespace::*[.='http://ns.esko-graphics.com/pagerangelist/1.0/'] and
namespace::*[.='http://ns.esko-graphics.com/pagerange/1.1/']
]">
<h3>Used ink on certain pages:</h3>
<xsl:for-each select="egPagL:pagelist/rdf:Seq/rdf:li">
<b>From page <xsl:value-of select="egPag:start"/> until <xsl:value-of select="egPag:end"/></b><br/>
Inkt nr's:

<!-- just ink numbers -->
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li">
<xsl:value-of select="node()"/><xsl:text>, </xsl:text>
</xsl:for-each><br/><br/>

<!-- try one, diden't work -->
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li">
<xsl:value-of select="ancestor::*[namespace::*[.='http://ns.esko-graphics.com/inkinfo/1.0/'] and namespace::*[.='http://ns.esko-graphics.com/grinfo/1.0/']]/egGr:inks/rdf:Seq/rdf:li[node()]/egInk:name"/>
</xsl:for-each><br/><br/>

<!-- try two, diden't work -->
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li">
<xsl:value-of select="/x:metadata/rdf:RDF/rdf:Description[namespace::*[.='http://ns.esko-graphics.com/inkinfo/1.0'] and namespace::*[.='http://ns.esko-graphics.com/grinfo/1.0/']]/egGr:inks/rdf:Seq/rdf:li[node()]/egInk:name"/>
</xsl:for-each><br/><br/>


</xsl:for-each>



<br/><br/>
</xsl:template>


</xsl:stylesheet>
Anyone who can help me?

Re: get value of different grandchild of ancestor

Posted: Tue Jan 19, 2010 11:11 am
by george
Replace your last template with something like below:

Code: Select all


<xsl:template match="rdf:Description[
namespace::*[.='http://ns.esko-graphics.com/pagerangelist/1.0/'] and
namespace::*[.='http://ns.esko-graphics.com/pagerange/1.1/']
]">

<h3>Used ink on certain pages:</h3>
<xsl:for-each select="egPagL:pagelist/rdf:Seq/rdf:li">
<b>
<xsl:text>From page </xsl:text>
<xsl:value-of select="egPag:start"/>
<xsl:text> until </xsl:text>
<xsl:value-of select="egPag:end"/>
</b>
<br/>
<xsl:text>Inkt nr's:</xsl:text>
<!-- ink numbers and corresponding names -->
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li">
<xsl:value-of select="."/>
<xsl:variable name="index" select="number(.)"/>
<xsl:text> (</xsl:text>
<xsl:value-of select="$inks[$index]/egInk:name"/>
<xsl:text>)</xsl:text>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each>
<br/><br/>
</xsl:for-each>
<br/><br/>
</xsl:template>
Basically you can select the sequence of colors in a variable and just get the one at position specified by its index.

Best Regards,
George

Re: get value of different grandchild of ancestor

Posted: Tue Jan 19, 2010 12:33 pm
by metalhammer
thanks,

but now Oxygen says the variable inks has not been declared.
How can I do that?

Re: get value of different grandchild of ancestor

Posted: Tue Jan 19, 2010 12:37 pm
by george
Sorry, I did not took all the changed fragment. Add the variable declaration, for example:

Code: Select all


<xsl:variable name="inks" select="//egGr:inks/rdf:Seq/*"/>  
Regards,
George

Re: get value of different grandchild of ancestor

Posted: Tue Jan 19, 2010 1:32 pm
by metalhammer
thanks, that works

But I want to tweak the code a little bit.

I want the process inks (see in egInk:type) to be first, then the pantone inks and then the designer inks.

I tried this by filtering the output to just process, and then repeating the code with filtering pantone, ...

But there is something wrong with my filter

Code: Select all


	<xsl:template match="rdf:Description[
namespace::*[.='http://ns.esko-graphics.com/pagerangelist/1.0/'] and
namespace::*[.='http://ns.esko-graphics.com/pagerange/1.1/']
]">

<h3>Used ink on certain pages:</h3>
<xsl:for-each select="egPagL:pagelist/rdf:Seq/rdf:li">
<b>
<xsl:text>From page </xsl:text>
<xsl:value-of select="egPag:start"/>
<xsl:text> until </xsl:text>
<xsl:value-of select="egPag:end"/>
</b>
<br/>
<xsl:text>Inkt kinds: </xsl:text>
<!-- ink numbers and corresponding names -->
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li[egInk:type='process']">

<xsl:variable name="inks" select="//egGr:inks/rdf:Seq/*" />
<xsl:variable name="index" select="number(.)"/>
<xsl:value-of select="$inks[$index]/egInk:name"/>
<xsl:if test="position()!=last()">, </xsl:if>
</xsl:for-each>
<br/><br/>
</xsl:for-each>
<br/><br/>
</xsl:template>

Re: get value of different grandchild of ancestor

Posted: Wed Jan 20, 2010 11:37 am
by george
I suggest using XSLT 2.0, if XSLT 1.0 is not a requirement for you. Changing the version attribute from the stylesheet element to 2.0 and putting the following template should get your desired result. The same can be done in XSLT 1.0 but requires either the node-set extension or to try to get directly the colors names, that is a different approach.

Code: Select all


<xsl:variable name="inks" select="//egGr:inks/rdf:Seq/*"/>  
<!-- esko artwork pages p30 -->
<xsl:template match="rdf:Description[
namespace::*[.='http://ns.esko-graphics.com/pagerangelist/1.0/'] and
namespace::*[.='http://ns.esko-graphics.com/pagerange/1.1/']
]" xml:space="default">

<h3>Used ink on certain pages:</h3>
<xsl:for-each select="egPagL:pagelist/rdf:Seq/rdf:li">
<b>
<xsl:text>From page </xsl:text>
<xsl:value-of select="egPag:start"/>
<xsl:text> until </xsl:text>
<xsl:value-of select="egPag:end"/>
</b>
<br/>
<xsl:text>Inkt kinds: </xsl:text>
<!-- ink numbers and corresponding names -->
<xsl:variable name="filtered">
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li">
<xsl:variable name="index" select="number(.)"/>
<xsl:if test="$inks[$index]/egInk:type='process'">
<xsl:copy-of select="$inks[$index]/egInk:name"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="$filtered/*" separator=","/>
<br/><br/>
</xsl:for-each>
<br/><br/>
</xsl:template>
Best Regards,
George

Re: get value of different grandchild of ancestor

Posted: Tue Jan 26, 2010 7:33 pm
by metalhammer
I'm gonna have to use XSLT 1.0

So I tried your suggestion about using node-set()
But I keep getting the following error:

Code: Select all


Ernst: fatal
Omschrijving: Cannot find a matching 1-argument function named {http://exslt.org/common}node-set()
Startlocatie: 609:0
I added

Code: Select all


xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl"
to the declared namespaces of my xslt, so that's not the problem.

My try to use node-set():

Code: Select all


	<xsl:template match="rdf:Description[
namespace::*[.='http://ns.esko-graphics.com/pagerangelist/1.0/'] and
namespace::*[.='http://ns.esko-graphics.com/pagerange/1.1/']
]">

<div class="tsstitelachtergrond"><h3>Used ink on certain pages:</h3></div>
<xsl:for-each select="egPagL:pagelist/rdf:Seq/rdf:li">
<b>
<xsl:text>From page </xsl:text>
<xsl:value-of select="egPag:start"/>
<xsl:text> until </xsl:text>
<xsl:value-of select="egPag:end"/>
</b>
<br/>
<xsl:text>Inkt kinds: </xsl:text>
<!-- ink numbers and corresponding names -->
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li">

<xsl:variable name="inks" select="//egGr:inks/rdf:Seq/*" />
<xsl:variable name="index" select="number(.)"/>
<xsl:value-of select="exsl:node-set($inks[$index])/egInk:type"/>
<xsl:if test="position()!=last()">, </xsl:if>
</xsl:for-each>
<br/>
</xsl:for-each>
</xsl:template>

Re: get value of different grandchild of ancestor

Posted: Thu Jan 28, 2010 4:57 pm
by george
It works ok for me with Xalan, Saxon 6 and Saxon 9. Look into the documentation for your XSLT processor, if it does not support that extension function find the equivalent that it supports.

Best Regards,
George

Re: get value of different grandchild of ancestor

Posted: Fri Jan 29, 2010 1:43 pm
by metalhammer
Apparently I only get the error using Saxon-HE, the other Saxons and Xalan work fine.

But I'm still having problems building the Xpath.

I just want the names of the process inks.
This is my best try:

Code: Select all


<xsl:value-of select="exsl:node-set($inks[$index])[rdf:li/egInk:type='process']/egInk:name"/>

Re: get value of different grandchild of ancestor

Posted: Fri Jan 29, 2010 7:02 pm
by george
Yes, because Saxon HE does not support EXSLT extension functions, see http://www.saxonica.com/feature-matrix.html.

But if you use Saxon 9 then you can use the XSLT 2.0 solution that I posted earlier.

For XSLT 1.0 you can use

Code: Select all


<xsl:variable name="inks" select="//egGr:inks/rdf:Seq/*"/> 
<!-- esko artwork pages p30 -->
<xsl:template match="rdf:Description[
namespace::*[.='http://ns.esko-graphics.com/pagerangelist/1.0/'] and
namespace::*[.='http://ns.esko-graphics.com/pagerange/1.1/']
]" xml:space="default">

<h3>Used ink on certain pages:</h3>
<xsl:for-each select="egPagL:pagelist/rdf:Seq/rdf:li">
<b>
<xsl:text>From page </xsl:text>
<xsl:value-of select="egPag:start"/>
<xsl:text> until </xsl:text>
<xsl:value-of select="egPag:end"/>
</b>
<br/>
<xsl:text>Inkt kinds: </xsl:text>
<!-- ink numbers and corresponding names -->
<xsl:variable name="filtered">
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li">
<xsl:variable name="index" select="number(.)"/>
<xsl:if test="$inks[$index]/egInk:type='process'">
<xsl:copy-of select="$inks[$index]/egInk:name"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="$filtered/*" separator=","/>
<br/><br/>
</xsl:for-each>
<br/><br/>
</xsl:template>
Regards,
George

Re: get value of different grandchild of ancestor

Posted: Sat Jan 30, 2010 5:18 pm
by metalhammer
I'm testing my xslt in Oxygen with Saxon. But I'm gonna use it in an applescript with a processor that supports xslt 1.0 and most of the exslt functions.
So I'm gonna stick with xslt 1.0 as long as I can.

Your code works for me, but I want the word "Process" writen before each ink name. I tried adjusting your code, but for some reason it doesn't works.

Code: Select all


	<xsl:variable name="inks" select="//egGr:inks/rdf:Seq/*"/>
<!-- esko artwork pages p30 -->
<xsl:template match="rdf:Description[
namespace::*[.='http://ns.esko-graphics.com/pagerangelist/1.0/'] and
namespace::*[.='http://ns.esko-graphics.com/pagerange/1.1/']
]" xml:space="default">

<div class="tsstitelachtergrond"><h3>Used ink on certain pages:</h3></div>
<xsl:for-each select="egPagL:pagelist/rdf:Seq/rdf:li">
<b>
<xsl:text>From page </xsl:text>
<xsl:value-of select="egPag:start+1"/>
<xsl:text> until </xsl:text>
<xsl:value-of select="egPag:end+1"/>
</b>
<br/>
<xsl:text>Inkt kinds: </xsl:text>
<!-- ink numbers and corresponding names -->
<xsl:variable name="filtered">
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li">
<xsl:variable name="index" select="number(.)"/>
<xsl:if test="$inks[$index]/egInk:type='process'">
<xsl:text>Process </xsl:text><xsl:copy-of select="$inks[$index]/egInk:name"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="$filtered/*" separator=", "/>
<br/><br/>
</xsl:for-each>
</xsl:template>

Re: get value of different grandchild of ancestor

Posted: Fri Feb 05, 2010 1:00 pm
by metalhammer
I just switched my xslt processor in my script to Saxon, so I can use XSLT 2.0.
Does that help?

Re: get value of different grandchild of ancestor

Posted: Fri Feb 05, 2010 4:21 pm
by sorin_ristache
Hello,

It does not matter if you use an XSLT 1.0 processor or an XSLT 2.0 processor because George posted an XSLT 1.0 solution so it works with both types of processor. The example below is also an XSLT 1.0 solution.

If you want to display the ink name only when the type is process just test the value of the egInk:type element with an xsl:if element to see if it is process. For example replace the last template from your stylesheet with the following one:

Code: Select all

<xsl:template match="rdf:Description[
namespace::*[.='http://ns.esko-graphics.com/pagerangelist/1.0/'] and
namespace::*[.='http://ns.esko-graphics.com/pagerange/1.1/']
]">

<xsl:variable name="inks" select="//egGr:inks/rdf:Seq/*"/>

<h3>Used ink on certain pages:</h3>
<xsl:for-each select="egPagL:pagelist/rdf:Seq/rdf:li">
<b>
<xsl:text>From page </xsl:text>
<xsl:value-of select="egPag:start"/>
<xsl:text> until </xsl:text>
<xsl:value-of select="egPag:end"/>
</b>
<br/>
<xsl:text>Inkt nr's:</xsl:text>
<!-- ink numbers and corresponding names -->
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li">
<xsl:value-of select="."/>
<xsl:variable name="index" select="number(.)"/>
<xsl:if test="$inks[$index]/egInk:type = 'process'">
<xsl:text> (Process </xsl:text>
<xsl:value-of select="$inks[$index]/egInk:name"/>
<xsl:text>)</xsl:text>
</xsl:if>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each>
<br/><br/>
</xsl:for-each>
<br/><br/>
</xsl:template>

Regards,
Sorin

Re: get value of different grandchild of ancestor

Posted: Fri Feb 05, 2010 6:09 pm
by metalhammer
thanks,

I adjusted your code a bit so all the process inks are first, then the pantone inks and then the designer inks.

Here it is:

Code: Select all


	<!-- esko artwork pages p30 -->
<xsl:template match="rdf:Description[
namespace::*[.='http://ns.esko-graphics.com/pagerangelist/1.0/'] and
namespace::*[.='http://ns.esko-graphics.com/pagerange/1.1/']
]">

<xsl:variable name="inks" select="//egGr:inks/rdf:Seq/*"/>

<div class="tsstitelachtergrond"><h3>Used ink on certain pages:</h3></div>
<xsl:for-each select="egPagL:pagelist/rdf:Seq/rdf:li">
<b>
<xsl:text>From page </xsl:text>
<xsl:value-of select="egPag:start"/>
<xsl:text> until </xsl:text>
<xsl:value-of select="egPag:end"/>
</b>
<br/>
<xsl:text>Ink kinds: </xsl:text>
<!-- ink numbers and corresponding names -->
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li">
<xsl:variable name="index" select="number(.)"/>
<xsl:choose>
<xsl:when test="$inks[$index]/egInk:type = 'process'">
<xsl:text>Process </xsl:text>
<xsl:value-of select="$inks[$index]/egInk:name"/>
<xsl:text>, </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li">
<xsl:variable name="index" select="number(.)"/>
<xsl:choose>
<xsl:when test="$inks[$index]/egInk:type = 'pantone'">
<xsl:text>Pantone </xsl:text>
<xsl:value-of select="$inks[$index]/egInk:name"/>
<xsl:text>, </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="egPag:inks/rdf:Seq/rdf:li">
<xsl:variable name="index" select="number(.)"/>
<xsl:choose>
<xsl:when test="$inks[$index]/egInk:type = 'designer'">
<xsl:value-of select="$inks[$index]/egInk:name"/>
<xsl:if test="position()!=last()"><xsl:text>, </xsl:text></xsl:if>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<br/>
</xsl:for-each>
</xsl:template>
Thanks for all the help!