Solved

Fix xsl to handle conditional value change

Posted on 2014-12-30
7
100 Views
Last Modified: 2014-12-31
I'm trying to get my xsl to conditionally change this specific content

<idoc:ItemRelativePath>
NVLAP - Quality
</idoc:ItemRelativePath>

to this:

<idoc:ItemRelativePath>
NVLAP/Quality
</idoc:ItemRelativePath>

if encountered.

My XSL doesn't work. I'm still getting "NVLAP - Quality" in my output. What have I got wrong?

Here's the xsl I'm working with:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:idoc="http://ns.inmagic.com/Presto/1.0/ContentConnector/DocumentParameters" exclude-result-prefixes="xsi">
      <xsl:output omit-xml-declaration="no" indent="yes"/>
      <xsl:strip-space elements="*"/>
      <xsl:template match="node()|@*">
            <xsl:copy>
                  <xsl:apply-templates select="node()|@*"/>
            </xsl:copy>
      </xsl:template>

      <xsl:template match="idoc:ItemName[normalize-space(.)]">
            <idoc:ItemName>
                  <xsl:value-of select="replace( ., '\.[^\.]+$', '')"/>
            </idoc:ItemName>
            <idoc:ItemFileName>
                  <xsl:value-of select="."/>
            </idoc:ItemFileName>
      </xsl:template>
      <xsl:template match="idoc:ItemRelativePath">
            <xsl:choose>
                  <xsl:when test="idoc:ItemRelativePath = 'NVLAP - Quality'">
                  <idoc:ItemRelativePath>
                        <xsl:value-of select="NVLAP/Quality"/>
                  </idoc:ItemRelativePath>
                  </xsl:when>
                  <xsl:otherwise>
                  <idoc:ItemRelativePath>
                        <xsl:value-of select="."/>
                  </idoc:ItemRelativePath>
                  </xsl:otherwise>
            </xsl:choose>
      </xsl:template>
</xsl:stylesheet>
0
Comment
Question by:GessWurker
  • 5
  • 2
7 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40524027
I see two issues

<xsl:template match="idoc:ItemRelativePath">
             <xsl:choose>
                   <xsl:when test="idoc:ItemRelativePath = 'NVLAP - Quality'">

1. the context of the template is idoc:ItemRelativePath
there is no child idoc:ItemRelativePath...
you need <xsl:when test=". = 'NVLAP - Quality'">

2. I see white-space before and after, so you need to normalize first
                   <xsl:when test="normalize-space(.) = 'NVLAP - Quality'">

the test in 2. should get you the fix
0
 

Author Comment

by:GessWurker
ID: 40524167
Hi Geert...  I'm not having success with your suggestions. Possibly, I've misunderstood you. Here's an input sample I'm working with.

<?xml version="1.0" encoding="UTF-8"?><pxf:FileDescription xmlns:pxf="http://ns.inmagic.com/Presto/1.0/ContentPipeline/ExifTool" xmlns:et="http://ns.exiftool.ca/1.0/" xmlns:ExifTool="http://ns.exiftool.ca/ExifTool/1.0/" xmlns:System="http://ns.exiftool.ca/File/System/1.0/" xmlns:File="http://ns.exiftool.ca/File/1.0/" xmlns:PDF="http://ns.exiftool.ca/PDF/PDF/1.0/" xmlns:XMP-x="http://ns.exiftool.ca/XMP/XMP-x/1.0/" xmlns:XMP-xmp="http://ns.exiftool.ca/XMP/XMP-xmp/1.0/" xmlns:XMP-xmpMM="http://ns.exiftool.ca/XMP/XMP-xmpMM/1.0/" xmlns:XMP-dc="http://ns.exiftool.ca/XMP/XMP-dc/1.0/" xmlns:idoc="http://ns.inmagic.com/Presto/1.0/ContentConnector/DocumentParameters" xmlns:d1p1="http://www.w3.org/1999/02/22-rdf-syntax-ns#" d1p1:about="E:/Apps/Inmagic/Presto/ImportStaging/ProofOfJurorService4012014_pdf_idoc_2014-12-19[21-12-39-863].pdf" et:toolkit="Image::ExifTool 8.50">
  <idoc:ItemURL>xpcc:///Copy_of_Network_Connector_268ea83b7f074da296495c5e1e82e035/Rovings/ProofOfJurorService4012014.pdf</idoc:ItemURL>
  <idoc:NativeURL>\\officesrv1\dbstore\Inmagic\Document Capture\Source\Analytical Testing Reports\Rovings\ProofOfJurorService4012014.pdf</idoc:NativeURL>
  <idoc:ConnectorRootPath>//officesrv1/dbstore/Inmagic/Document Capture/Source/Analytical Testing Reports</idoc:ConnectorRootPath>
  <idoc:ItemRelativePath>NVLAP - Quality</idoc:ItemRelativePath>
  <idoc:ItemName>ProofOfJurorService4012014.pdf</idoc:ItemName>
  <idoc:UID>//officesrv1/dbstore/Inmagic/Document Capture/Source/Analytical Testing Reports/NVLAP - Quality/ProofOfJurorService4012014.pdf</idoc:UID>
  <idoc:MimeType>application/pdf</idoc:MimeType>
  <idoc:Extension>.pdf</idoc:Extension>
  <idoc:ContentLength>311751</idoc:ContentLength>
  <idoc:CreationDate>12/19/2014 1:52:24 PM</idoc:CreationDate>
  <idoc:LastModificationDate>4/1/2014 9:00:23 PM</idoc:LastModificationDate>
  <ExifTool:ExifToolVersion>8.50</ExifTool:ExifToolVersion>
  <System:FileName>ProofOfJurorService4012014_pdf_idoc_2014-12-19[21-12-39-863].pdf</System:FileName>
  <System:Directory>E:/Apps/Inmagic/Presto/ImportStaging</System:Directory>
  <System:FileSize>304 kB</System:FileSize>
  <System:FileModifyDate>12/19/2014</System:FileModifyDate>
  <System:FilePermissions>rw-rw-rw-</System:FilePermissions>
  <File:FileType>PDF</File:FileType>
  <File:MIMEType>application/pdf</File:MIMEType>
  <PDF:PDFVersion>1.3</PDF:PDFVersion>
  <PDF:Linearized>Yes</PDF:Linearized>
  <PDF:CreateDate>04/01/2014</PDF:CreateDate>
  <PDF:ModifyDate>04/01/2014</PDF:ModifyDate>
  <PDF:PageCount>1</PDF:PageCount>
  <XMP-x:XMPToolkit>Adobe XMP Core 5.4-c005 78.147326, 2012/08/23-13:03:03        </XMP-x:XMPToolkit>
  <XMP-xmp:ModifyDate>04/01/2014</XMP-xmp:ModifyDate>
  <XMP-xmp:CreateDate>04/01/2014</XMP-xmp:CreateDate>
  <XMP-xmp:MetadataDate>04/01/2014</XMP-xmp:MetadataDate>
  <XMP-xmpMM:DocumentID>uuid:81605080-bfa5-44a5-b91e-9d679f19c26f</XMP-xmpMM:DocumentID>
  <XMP-xmpMM:InstanceID>uuid:1605ac43-b168-48e7-bcad-135c0f21c3e2</XMP-xmpMM:InstanceID>
  <XMP-dc:Format>application/pdf</XMP-dc:Format>
</pxf:FileDescription>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40524720
Well, you also missed the single quotes
 <xsl:value-of select="NVLAP/Quality"/>
should be
 <xsl:value-of select="'NVLAP/Quality'"/>
or even better
 <xsl:text>NVLAP/Quality</xsl:text>
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40524724
But, in the true spirit of XSLT
you would not use a xsl:choose
but a more specific template

    <xsl:template match="idoc:ItemRelativePath[normalize-space(.) = 'NVLAP - Quality']">
                <idoc:ItemRelativePath>
                    <xsl:text>NVLAP/Quality</xsl:text>
                </idoc:ItemRelativePath>
    </xsl:template>

and no extra template for when that value is not found, simply because that is redundant with the default processing
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 40524725
This stylesheet does exactly what you want

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:idoc="http://ns.inmagic.com/Presto/1.0/ContentConnector/DocumentParameters"
    exclude-result-prefixes="xsi">
    <xsl:output omit-xml-declaration="no" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="idoc:ItemName[normalize-space(.)]">
        <idoc:ItemName>
            <xsl:value-of select="replace( ., '\.[^\.]+$', '')"/>
        </idoc:ItemName>
        <idoc:ItemFileName>
            <xsl:value-of select="."/>
        </idoc:ItemFileName>
    </xsl:template>
    
    <xsl:template match="idoc:ItemRelativePath[normalize-space(.) = 'NVLAP - Quality']">
                <idoc:ItemRelativePath>
                    <xsl:text>NVLAP/Quality</xsl:text>
                </idoc:ItemRelativePath>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0
 

Author Closing Comment

by:GessWurker
ID: 40524754
A++, actually.

THANK YOU!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40525111
welcome
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now