[Portfolio] parsing template ?

Jon Wheat jwheat at messiah.edu
Mon Jul 27 14:04:35 PDT 2009


Thank you, that example helped resolve my parsing issue.  
I was pretty close with what I had, but as usual yours was far superior to mine... plus it worked <G>
 
getting the fileSelect indexes is the next issue to overcome, but I'll save that for tomorrow.  New day, fresh pot of coffee.
 
once again - thank you Noah and Erica, I do appreciate the time you take walking me through stupid things like this
 
-Jon

>>> Noah Botimer <botimer at umich.edu> 7/27/2009 4:41 PM >>>
Erica just asked me to provide clarification to this. Although I suggest looking at my other response for what I would do in this specific case, string parsing comes up often, and isn't obvious to most folks in XSLT.

You essentially end up programming like you're in Lisp (CAR and CDR, anyone?). That is, the template Erica mentions would be recursive. Since you're looking for stuff after the last slash, one way is to check if there is a slash and, if so, run the same template on the stuff after it, otherwise just returning the input. You could do it like this:

<xsl:templatename="after-last-slash">
    <xsl:paramname="someText"/>
    <xsl:choose>
        <xsl:whentest="contains($someText, '/')"><xsl:call-templatename="last-slash"><xsl:with-paramname="someText"select="substring-after($someText, '/')"/></xsl:call-template></xsl:when>
        <xsl:otherwise><xsl:value-ofselect="$someText"/></xsl:otherwise>
    </xsl:choose>
</xsl:template>

You then just call the after-last-slash template with the parameter someText being whatever you need to parse. You'll either end up outputting it immediately or capturing it in an xsl:variable for output somewhere else.

Cheers,
-Noah

On Jul 27, 2009, at 4:13 PM, Ackerman, Erica wrote:




Jon, I think you want to create a template that calls substring-before and substring-after to break the string up, saving the substring-before and the substring-after parts in variables. The template would then call itself again until there was no substring-after part. 
Erica
From:portfolio-bounces at collab.sakaiproject.org [mailto:portfolio-bounces at collab.sakaiproject.org] On Behalf Of Jon Wheat
Sent: Monday, July 27, 2009 4:01 PM
To: portfolio at collab.sakaiproject.org
Subject: [Portfolio] parsing template ?

I have a portfolio form that collects multiple attachments.

The resulting XML looks like this -

     <structuredData>
        <document>
          <docReflection> snipped </docReflection>
          <fileSelect>/attachment/2f0ae395-a3dd-493b-b9da-141395ad34ff/Matrices/8b842f05-a344-42a0-91c3-51f138d51f62/lang_c1.pdf</fileSelect>
          <fileSelect>/attachment/2f0ae395-a3dd-493b-b9da-141395ad34ff/Matrices/426b99d2-d514-4a08-ba9a-0d00ffd8e81d/lang_c2.pdf</fileSelect>
          <fileSelect>/attachment/2f0ae395-a3dd-493b-b9da-141395ad34ff/Matrices/c0afc9de-f294-49ec-bcfc-1e47a7d7908a/lang_c3.pdf</fileSelect>
        </document>
      </structuredData>

I'm now attempting to grab just the filenames for these files and am having difficulty both looping though the fileSelect(s) and parsing the urls so I can create simple a lang_c1.pdf link.

Does anyone have any template code that does this ?

- Jon
_______________________________________________
portfolio mailing list
portfolio at collab.sakaiproject.org
http://collab.sakaiproject.org/mailman/listinfo/portfolio

TO UNSUBSCRIBE: send email to portfolio-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/portfolio/attachments/20090727/b92707f0/attachment.html 


More information about the portfolio mailing list