cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

create external file with specific name

kmccain
3-Newcomer

create external file with specific name

Hi,


I need to create an external file from an xml document that extracts the content of certain key elements in a listing that is then processed for another use. I have this working in my FOSI stylesheet after following some instructions in the PTC Help Center and it extracts the data I want to an xxxx.exp file in the same folder. So far, so good. But the .exp file always takes the name of the parent element that the coding is used in, e.g. name.exp.


My problem is that I have several xml documents in the same folder and all of them need to create this .exp file. Since the style sheet always gives the file the same name no matter which file it is, they overwrite each other unless the writer is quick to rename his exp file.


Is there a way to name the .exp file created specifically either using FOSI or some kind of ACL so that I can add a sequential number to the created file name or make them specific to each document instance in some way?


KM

2 REPLIES 2

Hi Kim--

I don't know a way to change the name of the .exp file that a FOSI creates (though there may well be a way to do it--I am far from a FOSI expert). But I know for sure that this is pretty easy to do with ACL.

For example, if you wanted to write out a list of all the chapters in a document, with the title and ID attribute, in comma-separated format to read into Excel, you could use a function like this:

# params: doc is XML source document ID, filename is file to write data to
# assumes markup consists of chapters marked up like this:
# <chapter id="ch01"><title>First Chapter</title>.....</chapter>
# NB: Untested code; debugging is left as an exercise

function save_chapter_info(doc, filename) {

# open the file; for production code, you'd want to add some error handling
local f = open(filename, "w");

# collect the things we want to report on
local chapters[], c, title, id;
oid_find_children(oid_root(doc),chapters,"chapter");
for (c in chapters) {
title = oid_xpath_string(chapters[c],"title[1]");
id = oid_attr(chapters[c],"id");
# write the string to the data file
put(f, c . '," . title . ",' . id . "\n");
}
# done, close the file
close(f);
}

Hopefully you can generalize this pretty easily to the exact data you need to extract from your documents.

--Clay

Hi Kim,

You can put a usetext with userule=1 in a pseudo-element. So I'm thinking you could use system-func to call an ACL function that fillvals an existing pseudo-element (<extfile1.psu>,</extfile1.psu>) or a string variable name that contains the pseudo-element into a usetext source. The issue is how the ACL function determines which pseudo-element to return. Maybe ACL checks for existing file names. I am not an ACL expert. Others may have ideas on this.

Good luck!

Suzanne Napoleon
www.FOSIexpert.com
"WYSIWYG is last-century technology!"


Announcements

Top Tags