Link to home
Start Free TrialLog in
Avatar of GessWurker
GessWurker

asked on

Fix xsl to handle conditional value change

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>
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

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
Avatar of GessWurker
GessWurker

ASKER

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>
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>
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
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A++, actually.

THANK YOU!