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="x si">
<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[norma lize-space (.)]">
<idoc:ItemName>
<xsl:value-of select="replace( ., '\.[^\.]+$', '')"/>
</idoc:ItemName>
<idoc:ItemFileName>
<xsl:value-of select="."/>
</idoc:ItemFileName>
</xsl:template>
<xsl:template match="idoc:ItemRelativePa th">
<xsl:choose>
<xsl:when test="idoc:ItemRelativePat h = '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>
<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="x
<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[norma
<idoc:ItemName>
<xsl:value-of select="replace( ., '\.[^\.]+$', '')"/>
</idoc:ItemName>
<idoc:ItemFileName>
<xsl:value-of select="."/>
</idoc:ItemFileName>
</xsl:template>
<xsl:template match="idoc:ItemRelativePa
<xsl:choose>
<xsl:when test="idoc:ItemRelativePat
<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>
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:Fil eDescripti on 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/Inmagi c/Presto/I mportStagi ng/ProofOf JurorServi ce4012014_ pdf_idoc_2 014-12-19[ 21-12-39-8 63].pdf" et:toolkit="Image::ExifToo l 8.50">
<idoc:ItemURL>xpcc:///Copy _of_Networ k_Connecto r_268ea83b 7f074da296 495c5e1e82 e035/Rovin gs/ProofOf JurorServi ce4012014. pdf</idoc: ItemURL>
<idoc:NativeURL>\\officesr v1\dbstore \Inmagic\D ocument Capture\Source\Analytical Testing Reports\Rovings\ProofOfJur orService4 012014.pdf </idoc:Nat iveURL>
<idoc:ConnectorRootPath>// officesrv1 /dbstore/I nmagic/Doc ument Capture/Source/Analytical Testing Reports</idoc:ConnectorRoo tPath>
<idoc:ItemRelativePath>NVL AP - Quality</idoc:ItemRelative Path>
<idoc:ItemName>ProofOfJuro rService40 12014.pdf< /idoc:Item Name>
<idoc:UID>//officesrv1/dbs tore/Inmag ic/Documen t Capture/Source/Analytical Testing Reports/NVLAP - Quality/ProofOfJurorServic e4012014.p df</idoc:U ID>
<idoc:MimeType>application /pdf</idoc :MimeType>
<idoc:Extension>.pdf</idoc :Extension >
<idoc:ContentLength>311751 </idoc:Con tentLength >
<idoc:CreationDate>12/19/2 014 1:52:24 PM</idoc:CreationDate>
<idoc:LastModificationDate >4/1/2014 9:00:23 PM</idoc:LastModificationD ate>
<ExifTool:ExifToolVersion> 8.50</Exif Tool:ExifT oolVersion >
<System:FileName>ProofOfJu rorService 4012014_pd f_idoc_201 4-12-19[21 -12-39-863 ].pdf</Sys tem:FileNa me>
<System:Directory>E:/Apps/ Inmagic/Pr esto/Impor tStaging</ System:Dir ectory>
<System:FileSize>304 kB</System:FileSize>
<System:FileModifyDate>12/ 19/2014</S ystem:File ModifyDate >
<System:FilePermissions>rw -rw-rw-</S ystem:File Permission s>
<File:FileType>PDF</File:F ileType>
<File:MIMEType>application /pdf</File :MIMEType>
<PDF:PDFVersion>1.3</PDF:P DFVersion>
<PDF:Linearized>Yes</PDF:L inearized>
<PDF:CreateDate>04/01/2014 </PDF:Crea teDate>
<PDF:ModifyDate>04/01/2014 </PDF:Modi fyDate>
<PDF:PageCount>1</PDF:Page Count>
<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:Modify Date>
<XMP-xmp:CreateDate>04/01/ 2014</XMP- xmp:Create Date>
<XMP-xmp:MetadataDate>04/0 1/2014</XM P-xmp:Meta dataDate>
<XMP-xmpMM:DocumentID>uuid :81605080- bfa5-44a5- b91e-9d679 f19c26f</X MP-xmpMM:D ocumentID>
<XMP-xmpMM:InstanceID>uuid :1605ac43- b168-48e7- bcad-135c0 f21c3e2</X MP-xmpMM:I nstanceID>
<XMP-dc:Format>application /pdf</XMP- dc:Format>
</pxf:FileDescription>
<?xml version="1.0" encoding="UTF-8"?><pxf:Fil
<idoc:ItemURL>xpcc:///Copy
<idoc:NativeURL>\\officesr
<idoc:ConnectorRootPath>//
<idoc:ItemRelativePath>NVL
<idoc:ItemName>ProofOfJuro
<idoc:UID>//officesrv1/dbs
<idoc:MimeType>application
<idoc:Extension>.pdf</idoc
<idoc:ContentLength>311751
<idoc:CreationDate>12/19/2
<idoc:LastModificationDate
<ExifTool:ExifToolVersion>
<System:FileName>ProofOfJu
<System:Directory>E:/Apps/
<System:FileSize>304 kB</System:FileSize>
<System:FileModifyDate>12/
<System:FilePermissions>rw
<File:FileType>PDF</File:F
<File:MIMEType>application
<PDF:PDFVersion>1.3</PDF:P
<PDF:Linearized>Yes</PDF:L
<PDF:CreateDate>04/01/2014
<PDF:ModifyDate>04/01/2014
<PDF:PageCount>1</PDF:Page
<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/
<XMP-xmp:CreateDate>04/01/
<XMP-xmp:MetadataDate>04/0
<XMP-xmpMM:DocumentID>uuid
<XMP-xmpMM:InstanceID>uuid
<XMP-dc:Format>application
</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</x sl:text>
<xsl:value-of select="NVLAP/Quality"/>
should be
<xsl:value-of select="'NVLAP/Quality'"/>
or even better
<xsl:text>NVLAP/Quality</x
But, in the true spirit of XSLT
you would not use a xsl:choose
but a more specific template
<xsl:template match="idoc:ItemRelativePa th[normali ze-space(. ) = 'NVLAP - Quality']">
<idoc:ItemRelativePath>
<xsl:text>NVLAP/Quality</x sl: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
you would not use a xsl:choose
but a more specific template
<xsl:template match="idoc:ItemRelativePa
<idoc:ItemRelativePath>
<xsl:text>NVLAP/Quality</x
</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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
A++, actually.
THANK YOU!
THANK YOU!
welcome
<xsl:template match="idoc:ItemRelativePa
<xsl:choose>
<xsl:when test="idoc:ItemRelativePat
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