Two hyphens in an asset title breaks a format

Rob Knight's Avatar

Rob Knight

01 Apr, 2016 05:16 PM

I have an index block that generates the following output:

<system-page id="d255f1778072701764c820a6aad69371">  
        <name>arboretum-spring-sale</name>
        <is-published>true</is-published>
        <last-published-on>1459524410436</last-published-on>
        <last-published-by>stephens</last-published-by>
        <title>Arboretum holds Spring Plant Sale on Saturday, April 9</title>
        <summary>Annual sale offers a wide range of colorful, water-wise plants from Australia, New Zealand, South Africa, and California.</summary>
        <keywords>UC Santa Cruz Arboretum, UCSC Arboretum, Spring Plant Sale</keywords>
        <start-date>1459494000000</start-date>
        <display-name>Arboretum holds Spring Plant Sale on Saturday, April 9</display-name>
        <path>/2016/04/arboretum-spring-sale</path>
        <site>news</site>
        <link>site://news/2016/04/arboretum-spring-sale</link>
        <created-by>stephens</created-by>
        <created-on>1459522759785</created-on>
        <last-modified-by>stephens</last-modified-by>
        <last-modified>1459524390111</last-modified>
</system-page>

I'm using the following format to create a JSONP file:

<xsl:template match="system-page">  
        <xsl:text>{"name": "</xsl:text>
        <xsl:value-of select="name"/>
        <xsl:text>", "title": "</xsl:text>
        <xsl:value-of select="title"/>
        <xsl:text>", "url": "</xsl:text>
        <xsl:text>http://news.ucsc.edu</xsl:text>
        <xsl:value-of select="path"/>
        <xsl:text>.html</xsl:text>
        <xsl:text>", "date": "</xsl:text>
        <xsl:call-template name="format-date">
            <xsl:with-param name="date" select="start-date"/>
            <xsl:with-param name="mask">mmmm dd, yyyy</xsl:with-param>
        </xsl:call-template>
        <xsl:if test="system-data-structure/lead-image/image/path != '/'">
            <xsl:text>", "thumbnail": "</xsl:text>
            <xsl:text>http://news.ucsc.edu</xsl:text>
            <xsl:value-of select="system-data-structure/lead-image/image-thumb/path"/>
        </xsl:if>
        <xsl:text>"}</xsl:text>
        <xsl:if test="position() != last()">
            <xsl:text>, </xsl:text>
        </xsl:if>
    </xsl:template>

If the title element in the index block has two hyphens in it, the format doesn't work and I get a blank screen. If I remove the two hyphens from the title, it works again. I'm stumped as to why.

  1. 1 Posted by Rob Knight on 01 Apr, 2016 05:21 PM

    Rob Knight's Avatar

    Zip file of both files attached.

  2. 2 Posted by Ryan Griffith on 01 Apr, 2016 05:44 PM

    Ryan Griffith's Avatar

    Hi Rob,

    The issue is that -- is not valid XML, so the page rendering is failing.

    Your best bet would be to remove the double hyphen so you can output the value correctly. The best option I can think of is to use a Xalan function to replace double hyphens with a single one. Such a function would look something like:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="hh" version="1.0" xmlns:hh="http://www.hannonhill.com/XSL/Functions" xmlns:xalan="http://xml.apache.org/xalan">
    
      ...
      
      <xsl:template match="system-page">  
          <xsl:text>{"name": "</xsl:text>
          <xsl:value-of select="name"/>
          <xsl:text>", "title": "</xsl:text>
          <xsl:value-of select="hh:replaceDoubleHyphen(string(title))"/>
          <xsl:text>", "url": "</xsl:text>
          <xsl:text>http://news.ucsc.edu</xsl:text>
          <xsl:value-of select="path"/>
          <xsl:text>.html</xsl:text>
          <xsl:text>", "date": "</xsl:text>
          <xsl:call-template name="format-date">
              <xsl:with-param name="date" select="start-date"/>
              <xsl:with-param name="mask">mmmm dd, yyyy</xsl:with-param>
          </xsl:call-template>
          <xsl:if test="system-data-structure/lead-image/image/path != '/'">
              <xsl:text>", "thumbnail": "</xsl:text>
              <xsl:text>http://news.ucsc.edu</xsl:text>
              <xsl:value-of select="system-data-structure/lead-image/image-thumb/path"/>
          </xsl:if>
          <xsl:text>"}</xsl:text>
          <xsl:if test="position() != last()">
              <xsl:text>, </xsl:text>
          </xsl:if>
      </xsl:template>
      
      ...
    
      <xalan:component functions="replaceDoubleHyphen" prefix="hh">
        <xalan:script lang="javascript">
        <![CDATA[
          function replaceDoubleHyphen(str) {
            return str.replace(/-{2,}/g, '-');
          };
        ]]>
        </xalan:script>
      </xalan:component>
    </xsl:stylesheet>
    
  3. 3 Posted by Rob Knight on 01 Apr, 2016 06:20 PM

    Rob Knight's Avatar

    Thank you for your prompt reply, Ryan! The double hyphen is meant to mimic an mdash. Out of curiosity, is there any way to get something like an mdash in a title? It seems like I cannot use the HTML entity code for it.

  4. 4 Posted by Rob Knight on 01 Apr, 2016 06:25 PM

    Rob Knight's Avatar

    Never mind. I see that the UTF character code works in titles.

  5. 5 Posted by Ryan Griffith on 01 Apr, 2016 08:28 PM

    Ryan Griffith's Avatar

    You got it, Rob. You should be able to use the numeric entity to render an mdash. To confirm, were you able to get things working?

    Please let me know if you have any questions.

    Thanks!

  6. 6 Posted by Rob Knight on 03 Apr, 2016 09:10 PM

    Rob Knight's Avatar

    Do Xalan components need to be enabled in preferences or anything like that? I've tried to code above and it doesn't work. It fails silently with no error message, similar to my original script.

  7. 7 Posted by Rob Knight on 03 Apr, 2016 09:14 PM

    Rob Knight's Avatar

    I see that they do. We have them enabled in our setup, so I'm not sure why it isn't working.

  8. 8 Posted by Ryan Griffith on 04 Apr, 2016 12:33 PM

    Ryan Griffith's Avatar

    Hi Rob,

    Correct, there is an Enable Xalan JavaScript system preference you will want to ensure is checked.

    If it is not working, please feel free to attach your Format and sample XML that is being applied to the Format and I would be happy to help take a closer look.

    Thanks!

  9. 9 Posted by Rob Knight on 04 Apr, 2016 04:34 PM

    Rob Knight's Avatar

    Here is my XML:

    <?xml version="1.0" encoding="UTF-8"?>  
    <system-index-block name="Last 10 articles" type="content_type" current-time="1459786946747">  
        <system-page id="d3cd75f18072701764c820a6048685c2">
            <name>brca-exchange</name>
            <is-published>true</is-published>
            <last-published-on>1459782746898</last-published-on>
            <last-published-by>stephens</last-published-by>
            <title>BRCA Exchange aggregates publicly accessible data on breast cancer genes</title>
            <summary>UC Santa Cruz Genomics Institute led development of a web portal for patients, clinicians, and researchers.</summary>
            <keywords>Genomics Institute, David Haussler, Benedict Paten, BRCA Exchange, BRCA Challenge, Global Alliance for Genomics and Health, GA4GH</keywords>
            <start-date>1459782000000</start-date>
            <display-name>BRCA Exchange aggregates publicly accessible data on breast cancer genes</display-name>
            <path>/2016/04/brca-exchange</path>
            <site>news</site>
            <link>site://news/2016/04/brca-exchange</link>
            <created-by>stephens</created-by>
            <created-on>1459547369657</created-on>
            <last-modified-by>stephens</last-modified-by>
            <last-modified>1459782727338</last-modified>
            <dynamic-metadata>
                <name>category-divisions</name>
                <value>Engineering</value>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>category-arts</name>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>category-engineering</name>
                <value>Biomolecular Engineering</value>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>category-humanities</name>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>category-pbsci</name>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>category-socsci</name>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>category-landing-pages</name>
                <value>Research</value>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>category-audience</name>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>category-activity</name>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>category-values</name>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>category-topics</name>
                <value>Human Health</value>
                <value>Genomics</value>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>category-placement</name>
                <value>Secondary Story</value>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>type</name>
                <value>Regular News</value>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>category-profile</name>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>site-url</name>
            </dynamic-metadata>
            <dynamic-metadata>
                <name>number-displayed</name>
            </dynamic-metadata>
            <system-data-structure definition-path="Campus Home Environment/News Article">
                <contact>
                    <name>Tim Stephens</name>
                    <title />
                    <phone />
                    <email>[email blocked]</email>
                </contact>
                <video>
                    <embed />
                    <width />
                    <caption />
                </video>
                <lead-image>
                    <image type="file">
                        <content />
                        <path>/2016/04/images/global-alliance-400.jpg</path>
                        <link>site://news/2016/04/images/global-alliance-400.jpg</link>
                        <site>news</site>
                        <name>global-alliance-400.jpg</name>
                        <display-name>global-alliance-400.jpg</display-name>
                    </image>
                    <image-alt>Global Alliance logo</image-alt>
                    <image-thumb type="file">
                        <content />
                        <path>/2016/04/images/brca-challenge-thumb.jpg</path>
                        <link>site://news/2016/04/images/brca-challenge-thumb.jpg</link>
                        <site>news</site>
                        <name>brca-challenge-thumb.jpg</name>
                        <display-name>brca-challenge-thumb.jpg</display-name>
                    </image-thumb>
                    <image-thumb-alt>BRCA Challenge logo</image-thumb-alt>
                    <image-caption />
                </lead-image>
                <secondary-images>
                    <image type="file">
                        <content />
                        <path>/2016/04/images/brca-exchange-300.jpg</path>
                        <link>site://news/2016/04/images/brca-exchange-300.jpg</link>
                        <site>news</site>
                        <name>brca-exchange-300.jpg</name>
                        <display-name>brca-exchange-300.jpg</display-name>
                    </image>
                    <image-alt>BRCA Exchange logo</image-alt>
                    <image-caption />
                </secondary-images>
                <secondary-images>
                    <image type="file">
                        <content />
                        <path>/2015/07/images/benedict-paten-300.jpg</path>
                        <link>site://news/2015/07/images/benedict-paten-300.jpg</link>
                        <site>news</site>
                        <name>benedict-paten-300.jpg</name>
                        <display-name>benedict-paten-300.jpg</display-name>
                    </image>
                    <image-alt>Benedict Paten</image-alt>
                    <image-caption>Benedict Paten</image-caption>
                </secondary-images>
                <article-subhead>UC Santa Cruz Genomics Institute led development of the web portal for patients, clinicians, and researchers seeking information on BRCA1 and BRCA2 gene variants</article-subhead>
                <article-text>
                    <p>A team at the 
                        <a href="https://genomics.soe.ucsc.edu/">UC Santa Cruz Genomics Institute</a> working with the BRCA Challenge, a demonstration project of the 
                        <a href="https://genomicsandhealth.org/">Global Alliance for Genomics and Health</a> (GA4GH), has developed an important new resource, the BRCA Exchange web portal, which brings together genomic and clinical data on the genes BRCA1 and BRCA2.
                    </p>
                    <p>BRCA1 and BRCA2 are tumor suppressor genes, and certain mutations in them increase the risk of breast, ovarian, and other cancers. They are now among the most thoroughly studied genes in the human genome, and thousands of variants of each gene (versions with small differences in their DNA sequences) have been identified. Some variants are harmless or benign, others are deleterious, and for many variants the clinical significance remains uncertain.</p>
                    <p>BRCA Challenge is an international effort to advance understanding of these genes and their role in cancer by pooling all of the available genomic and clinical data. Improved understanding of genetic variation in these genes has the potential to improve patient diagnoses and disease prevention.</p>
                    <p>The BRCA Exchange is the first product of the BRCA Challenge, which released the newest version of the web portal on Sunday, April 3, in advance of the annual meeting of the 
                        <a href="http://www.ichg2016.org/index.html">International Congress of Human Genetics</a> (ICHG) in Kyoto, Japan.
                    </p>
                    <p>"As a result of this global effort, we were able to create the largest database of BRCA data in the world, providing a comprehensive resource that people can refer to when they get the results of a genetic test and want to know the clinical significance of particular BRCA gene variants," said UC Santa Cruz research scientist Benedict Paten, who led the Genomics Institute's work on the BRCA Exchange.</p>
                    <p>
                        <strong>International collaboration</strong>
                    </p>
                    <p>David Haussler, scientific director of the Genomics Institute and a cofounder of the Global Alliance for Genomics and Health, noted that international collaboration is essential to realize the full potential of genomic data. "The BRCA Exchange is a significant milestone in advancing the Global Alliance's mission of enabling the sharing of genomic and clinical data to improve human health," Haussler said.</p>
                    <p>The BRCA Exchange is a publicly accessible web portal that provides a simple interface for patients, clinicians, and researchers to access curated expert interpretations and some supporting evidence for genetic variants identified in BRCA1 and BRCA2. Since its initial beta launch in October 2015, the BRCA Exchange has supported clinical decision-making by allowing any web user to search all BRCA1 and BRCA2 genetic variants that have been classified by the international 
                        <a href="http://enigmaconsortium.org/">ENIGMA consortium</a> and to easily access the background rationale for classification.
                    </p>
                    <p>"The BRCA Challenge project represents the most comprehensive effort to date to pool BRCA variants from multiple international databases as a vehicle to provide supporting evidence for BRCA variant classifications in the public domain," said Amanda Spurdle, chair of the ENIGMA consortium steering committee and Head of the Molecular Cancer Epidemiology Laboratory, QIMR Berghofer Medical Research Institute, Brisbane, Australia.</p>
                    <p>The new release will include an additional tier that allows web users, after agreeing to a disclaimer and data use policy, to interact with data on genetic variants that have not yet been expert classified and whose clinical significance is therefore not yet understood. This represents the first time that all publicly available BRCA1 and BRCA2 variant data contained in databases such as ClinVar, LOVD, ExAC, and the 1000 Genomes Project have been pooled in a single, federated resource.</p>
                    <p>
                        <strong>&amp;#65279;Collective knowledge</strong>
                    </p>
                    <p>The exchange allows researchers, clinicians, and others to simultaneously search across the world's collective knowledge on the genes. The updated portal integrates information on more than 13,000 genetic variants from several national databases.</p>
                    <p>"We are pleased that after such a short period, we have already received feedback from users around the world who have accessed the portal for understanding BRCA1 and BRCA2 variants," said Stephen Chanock, director of the National Cancer Institute's Division of Cancer Epidemiology and Genetics and co-chair of the BRCA Challenge's Steering Committee.</p>
                    <p>The BRCA Exchange will enable the development of a federated network to share BRCA data using the application programming interface (API) developed by the GA4GH Data Working Group, co-chaired by Haussler. Such technical capabilities, developed in conjunction with members of the BRCA Challenge's Evidence Gathering Group, will allow organizations around the globe to share their data directly with the BRCA Exchange.</p>
                    <p>"By aggregating genomic and clinical data from around the world, the BRCA Exchange will significantly expand clinical impact because it will allow us to bring together currently siloed datasets to facilitate classifying variants of uncertain significance and resolving those with differing interpretations," said Heidi Rehm, director of the Laboratory for Molecular Medicine at Partners Healthcare and member of the BRCA Challenge's Steering Committee.</p>
                    <p>Version 1.0 of the BRCA Exchange, which is expected to launch later this year, will offer a third tier of access, visible only to credentialed users. This controlled access space will allow for improved variant classification by aggregating and hosting case-level evidence.</p>
                    <p>Development of the BRCA Exchange was funded primarily by the U.S. National Institutes of Health through the Center for Big Data in Translational Genomics, a multi-institutional partnership based at UC Santa Cruz.</p>
                    <p>The Global Alliance for Genomics and Health is an international, non-profit alliance formed to accelerate the potential of genomic medicine to advance human health. Bringing together over 350 leading organizations working in healthcare, research, disease and patient advocacy, life science, and information technology, GA4GH members are working together to create a common framework of tools, methods, and harmonized approaches and supporting demonstration projects to enable the responsible, voluntary, and secure sharing of genomic and clinical data.</p>
                </article-text>
                <comments />
                <show-updated />
                <admin>
                    <audience />
                    <admin /></admin>
                <related-links>
                    <page>
                        <path>/</path>
                    </page>
                    <symlink>
                        <path>/</path>
                    </symlink>
                    <url>http://</url>
                    <title />
                </related-links>
                <profile-content>
                    <thumb>
                        <path>/</path>
                    </thumb>
                    <thumb-alt />
                    <title />
                    <description />
                </profile-content>
                <events>
                    <end-date />
                </events>
            </system-data-structure>
        </system-page>
    </system-index-block>
    

    And my XSL format:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="hh" version="1.0" xmlns:hh="http://www.hannonhill.com/XSL/Functions" xmlns:xalan="http://xml.apache.org/xalan">  
        <xsl:strip-space elements="*"/>    
        <xsl:include href="/formats/Format Date"/>
        <xsl:template match="text()"><xsl:value-of select="normalize-space(.)"/></xsl:template> 
        <xsl:template match="//system-index-block">
            <!--
                Must be NO WHITESPACE between <xsl:comment> and #START-ROOT-CODE,
                same for #END-ROOT-CODE and </xsl:comment>
            -->
            <xsl:comment>#protect-top
                <xsl:text>latest({</xsl:text>
                <xsl:text>"items": [</xsl:text>
                <xsl:apply-templates select="//system-page[not(@current)]"/>
                <xsl:text>]})</xsl:text>
            #protect-top</xsl:comment>
        </xsl:template>
    
        <!--
            Simple example to output {"name": "system-name", "title": "Title
            Metadata"}
        -->
        <xsl:template match="system-page">
            <xsl:text>{"name": "</xsl:text>
            <xsl:value-of select="name"/>
            <xsl:text>", "title": "</xsl:text>
            <xsl:value-of select="hh:replaceDoubleHyphen(string(title))"/>
            <xsl:text>", "url": "</xsl:text>
            <xsl:text>http://news.ucsc.edu</xsl:text><xsl:value-of select="path"/><xsl:text>.html</xsl:text>
            <xsl:text>", "date": "</xsl:text>
            <xsl:call-template name="format-date">
                <xsl:with-param name="date" select="start-date"/>
                <xsl:with-param name="mask">mmmm dd, yyyy</xsl:with-param>
            </xsl:call-template>
            <xsl:if test="system-data-structure/lead-image/image/path != '/'">
                <xsl:text>", "thumbnail": "</xsl:text>
                <xsl:text>http://news.ucsc.edu</xsl:text><xsl:value-of select="system-data-structure/lead-image/image-thumb/path"/>
            </xsl:if>
            <xsl:text>"}</xsl:text>
            <xsl:if test="position() != last()">
                <xsl:text>, </xsl:text>
            </xsl:if>
        </xsl:template>
    
        <xalan:component functions="replaceDoubleHyphen" prefix="hh">
            <xalan:script lang="javascript">
            <![CDATA[
                function replaceDoubleHyphen(str) {
                    return str.replace(/-{2,}/g, '-');
                };
            ]]>
            </xalan:script>
      </xalan:component>
    
    </xsl:stylesheet>
    
  10. 10 Posted by Ryan Griffith on 05 Apr, 2016 02:00 PM

    Ryan Griffith's Avatar

    Hi Rob,

    Unfortunately, I was not able to reproduce the issue in my test instance. After adding a double-hyphen to the sample XML you provided, I was getting the following which appears to be the expected output:

    <!--#protect-top
                latest({"items": [{"name": "brca-exchange", "title": "BRCA Exchange aggregates publicly accessible data on breast cancer - genes", "url": "http://news.ucsc.edu/2016/04/brca-exchange.html", "date": "1459782000000", "thumbnail": "http://news.ucsc.edu/2016/04/images/brca-challenge-thumb.jpg"}]})
            #protect-top-->
    

    I also tried attaching the XML Block and Format to a page to make sure it renders and it does.

    Please let me know if you have any questions.

    Thanks!

  11. Tim closed this discussion on 25 May, 2016 05:30 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM