Solved

Fix xsl to handle conditional value change

Posted on 2014-12-30
7
103 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

791 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