Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Fix xsl to handle conditional value change

Posted on 2014-12-30
7
Medium Priority
?
110 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

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 …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

885 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