Solved

Adjust xslt to copy unmanipulated content to new line

Posted on 2014-12-19
3
108 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
ID: 40510040
<?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
ID: 40510074
Perfect! (Just like always.)  Thanks!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40510110
welcome
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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