Solved

Adjust xslt to copy unmanipulated content to new line

Posted on 2014-12-19
3
104 Views
Last Modified: 2014-12-19
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>
0
Comment
Question by:GessWurker
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
Comment Utility
<?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(.)]">
        <idoc:ItemName><xsl:value-of select="replace( ., '\.[^\.]+$', '')"/></idoc:ItemName>
        <idoc:ItemFileName><xsl:value-of select="."/></idoc:ItemFileName>      
    </xsl:template>
</xsl:stylesheet>
0
 

Author Comment

by:GessWurker
Comment Utility
Perfect! (Just like always.)  Thanks!
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
welcome
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

7 Experts available now in Live!

Get 1:1 Help Now