Link to home
Start Free TrialLog in
Avatar of GessWurker
GessWurker

asked on

Adjust xslt to copy unmanipulated content to new line

I'm using the xslt below to strip out file extensions. Now, I'd like to also copy the unstripped complete file name into another line so that the output includes both the file name without ext and the file name WITH the ext.:

  <idoc:ItemName>filename</idoc:ItemName>    [extension stripped]
  <idoc:ItemFileName>filename.ext</idoc:ItemFileName>  [original file name, including extension]

Here's the transform (thanks to Gertone!):

<?xml version="1.0" encoding="utf-8"?>
<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">
    <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(.)]">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
           <xsl:value-of select="replace( ., '\.[^\.]+$', '')"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Here's some test input:

<?xml version="1.0" standalone="yes"?>
<idoc:FileDescription xmlns:idoc="http://ns.inmagic.com/Presto/1.0/ContentConnector/DocumentParameters">
  <idoc:ItemURL>xpcc:///Copy_of_NC_268ea83b7f074da296495c5e1e82e035/Chopped Strand/testing123.pdf</idoc:ItemURL>
  <idoc:NativeURL>\\serverName\dbstore\Inmagic\dc\Source\Analytical Testing Reports\Chopped Strand\testing123.pdf</idoc:NativeURL>
  <idoc:ConnectorRootPath>//serverName/dbstore/Inmagic/dc/Source/Analytical Testing Reports</idoc:ConnectorRootPath>
  <idoc:ItemRelativePath>Chopped Strand</idoc:ItemRelativePath>
  <idoc:ItemName>testing123.pdf</idoc:ItemName>
  <idoc:UID>//serverName/dbstore/Inmagic/Document Capture/Source/Analytical Testing Reports/Chopped Strand/testing123.pdf</idoc:UID>
  <idoc:MimeType>application/pdf</idoc:MimeType>
  <idoc:Extension>.pdf</idoc:Extension>
  <idoc:ContentLength>163212</idoc:ContentLength>
  <idoc:CreationDate>10/8/2014 5:46:08 PM</idoc:CreationDate>
  <idoc:LastModificationDate>10/8/2014 4:26:22 PM</idoc:LastModificationDate>
</idoc:FileDescription>
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
Avatar of GessWurker
GessWurker

ASKER

Perfect! (Just like always.)  Thanks!