[daisy] Re: daisy Digest, Vol 25, Issue 24

Paul Focke paul at outerthought.org
Thu Oct 19 02:48:04 CDT 2006


Hello,

Diane Soini wrote:
> So I muddled my way through and actually created a document type-specific
> style sheet with a query in it. Several issues I cannot figure out:
>
> 1) My query is looking up documents based on the document type. I would
> like to also look up documents based on a field, but have it match the
> field with the document. Something like:
> <p:query>select name, $Vertical where documentType='CaseStudy' and
> $Vertical = <the same value of the current page doing this query></p:query>
>
> I am not sure how to do that.
You can make use of the ContextDoc() function in the query language. If 
you are running the query inside a document or a custom publisher 
request you'll have access to this.

select name, $Vertical where documentType='CaseStudy' and $Vertical = ContextDoc($Vertical)


>
> 2) My $Vertical field is a multi-value field. When I loop through the
> results, I can't get the field out.
> <h3>Case Studies</h3>
> <ul>
> <xsl:for-each
> select="../p:group[@id='casestudies']/d:searchResult/d:rows/d:row">
> <li><a
> href="{$documentBasePath}{@documentId}?branch={@branchId}&amp;language={@languageId}">
> <xsl:value-of select="d:value[1]"/>
> [[HOW DO I GET THE FIELD OUT?? d:value = d:value[1], d:value[2] doesn't
> give me anything, . gives me the field and the name. I can't get the field
> out by itself]]
> </a>
> </li>
> </xsl:for-each>
> </ul>
Aha ! A multivalue field. The values should then be stored in a 
d:multiValue tag
So your xsl might want to look like this
<ul>
<xsl:apply-templates 
select="../p:group[@id='casestudies']/d:searchResult/d:rows/d:row"/>
</ul>
<xsl:template match="d:row">
<li>
<a 
href="{$documentBasePath}{@documentId}?branch={@branchId}&amp;language={@languageId}">
<!-- You might want to filter this to only catch d:value d:multiValue 
d:xmlValue d:linkValue and/or d:hierarchyValue -->
<xsl:apply-templates select="./*"/>
</a>
</li>
</xsl:template>



<xsl:template match="d:value">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="d:multiValue">
<xsl:for-each select="*">
<xsl:if test="position() > 1">, </xsl:if>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>

A good resource to look at when you are doing query styling is in the 
default skin xslt/searchresults.xsl
>
> 3) To make matters worse, I can't get the individual values out of my
> multi-value field. It's just a lump of one value all mushed together. How
> do I get the values out as an array, and how do I loop through the array?
> Or do multi-values not really work?
Answer is in the previous response
>
> 4) I'm obviously using the query to display a list. However, I don't want
> to show the list or the heading if there are no matches with the verticals.
> How do I determine that there are no relevant results?
> Since my current query is this:
> <p:query>select name, $Vertical where documentType='CaseStudy'</p:query>
> I get all the documents even if they are the wrong ones. I can't figure out
> how to set a variable or determine somehow whether the list has any
> relevant case studies until too late in the HTML. I don't want to output
> anything if none of the case studies match.
>
>
Well if your query contains a filter on $Vertical (see answer1) then 
you'll only get the case studies you want. In order to know whether to 
show the heading or not check the row count.

HTH,

Paul


More information about the daisy mailing list