?
Solved

Adjust xslt to copy unmanipulated content to new line

Posted on 2014-12-19
3
Medium Priority
?
119 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

741 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