Solved

Adjust xslt to copy unmanipulated content to new line

Posted on 2014-12-19
3
106 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

864 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

19 Experts available now in Live!

Get 1:1 Help Now