3

I am trying to get the extendedDescription field with parentheses around it inline with Description, except when there is no extendedDescription.

I have found a lot of answers on formatting outputs and if statements. But, I am not a programmer and have not been able to get anything to work the way I would like it to.

If anybody could help me out I would appreciate it. Thank you!

Here is the code:

 <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:inr="http://mycompany.com/mynamespace">
    <xsl:include href="../format.xsl"/>
    <!-- TDS CR5 Format -->
    <xsl:output method="text" media-type="text/plain" encoding="iso-8859-1"/>
    <xsl:template match="/">
          <xsl:variable name="gridOut" select="inr:SetGridOut(number(InRoads/@outputGridScaleFactor))" />
        <xsl:choose>
            <xsl:when test="$xslShowHelp = 'true'">
                <xsl:call-template name="StyleSheetHelp"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:for-each select="//GeometryPoint[@name]">
                    <xsl:text/>
                    <xsl:value-of select="@name"/><xsl:text>,</xsl:text>
                    <xsl:value-of select="inr:northingFormat(number(@northing), $xslNorthingPrecision)"/><xsl:text>,</xsl:text>
                    <xsl:value-of select="inr:eastingFormat(number(@easting), $xslEastingPrecision)"/><xsl:text>,</xsl:text>
                    <xsl:value-of select="inr:elevationFormat(number(@elevation), $xslElevationPrecision)"/><xsl:text>,</xsl:text>
                    <xsl:value-of select="@description"/>(<xsl:value-of select="@extendedDescription"/>)<xsl:text>&#xd;</xsl:text>                                  
                </xsl:for-each>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="StyleSheetHelp">
        <xsl:text>Notes&#xd;&#xd;</xsl:text>
        <xsl:text>    You must include at least one cogo point in the Cogo&#xd;</xsl:text>
        <xsl:text>    Points &gt; Include field or one horizontal alignment with&#xd;</xsl:text>
        <xsl:text>    named points in the Horizontal Alignments &gt; Include&#xd;</xsl:text>
        <xsl:text>    field on the Tools &gt; XML Reports &gt; Geometry command to&#xd;</xsl:text>
        <xsl:text>    get results from this report.&#xd;&#xd;</xsl:text>
        <xsl:text>    Most style sheets in the DataCollection directory do&#xd;</xsl:text>
        <xsl:text>    not honor Tools &gt; Format Options with the exception of&#xd;</xsl:text>
        <xsl:text>    precision, where practical.&#xd;&#xd;</xsl:text>
        <xsl:text>Copyright 2006 Bentley Systems, Inc&#xd;</xsl:text>
    </xsl:template>
</xsl:stylesheet>

The output here is good, except when there is no extendedDescription, because I get () in the the resulting file.

Example output(present):

CS300,848822.7010,617517.7670,1022.26,6615(SES#44) 
CSG002,859658.2240,607167.2050,998.76,6652()

Example output(wanted):

CS300,848822.7010,617517.7670,1022.26,6615(SES#44) 
CSG002,859658.2240,607167.2050,998.76,6652

Again Thank you to anyone that can help me out.

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
john z
  • 33
  • 3

1 Answers1

3

Try changing:

(<xsl:value-of select="@extendedDescription"/>)

to:

<xsl:if test="string(@extendedDescription)">
  <xsl:value-of select="concat('(',@extendedDescription,')')"/>
</xsl:if>
Daniel Haley
  • 51,389
  • 6
  • 69
  • 95
  • And if for some bizarre reason you have to do it in pure xpath, see https://stackoverflow.com/q/971067/1405588 – o11c Sep 19 '17 at 00:10
  • @o11c that post only applies to XPath 1.0. Later XPath versions have a conditional expression. – Michael Kay Sep 19 '17 at 08:33
  • Also, you might prefer (XPath 3.1): `` – Michael Kay Sep 19 '17 at 08:37
  • @MichaelKay the second answer covers xpath 2. But xpath 1 is still the only relevant version, since it's the only one with an open-source C implementation. – o11c Sep 19 '17 at 16:26
  • Well I guess people who like using ancient languages like using ancient languages... But there was no mention of C in the question, so I don't quite see the relevance. – Michael Kay Sep 19 '17 at 22:47