Solved

Fix xsl to handle conditional value change

Posted on 2014-12-30
7
101 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
3 Use Cases for Connected Systems

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

 
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

3 Use Cases for Connected Systems

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

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

13 Experts available now in Live!

Get 1:1 Help Now