XPROC - Generation of files in secondary port - xproc

My requirement is to generate one XML file and few HTML files in the secondary port. I have configured few steps in XProc.
Here’s the sample code:
<p:xslt name="create-document">
<p:input port="stylesheet">
<p:document href="stylesheet.xsl" />
</p:input>
</p:xslt>
<p:for-each>
<p:iteration-source>
<p:pipe step="create-document" port="secondary" />
</p:iteration-source>
<p:store>
<p:with-option name="doctype-public" select="'-//W3C//DTD XHTML 1.0 Frameset//EN'" />
<p:with-option name="doctype-system" select="'http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd'" />
<p:with-option name="encoding" select="'UTF-8'" />
<p:with-option name="media-type" select="'text/html'" />
<p:with-option name="method" select="'xhtml'" />
<p:with-option name="omit-xml-declaration" select="'no'" />
</p:store>
</p:for-each>
The problem here is HTML file is generated properly. And the XML file is generated, but I am not able to view the XML content. Instead it displays everything in HTML format.This is because of <p:store> in the above code snippet.
How do you have two <p:store> steps? (One for HTML and the other for XML)

It would be nice if you could somehow determine with which xsl:result-document parameters each document on the secondary output was written. You would be able to duplicate those for your p:store. But you can derive other things from each document. You can retrieve the document name using base-uri(), and you can look at for instance the root element. You can put these values in a variable using:
<p:variable name="path" select="base-uri(/*)"/>
<p:variable name="root" select="local-name(/*)"/>
(Put these just below the p:iteration-source.)
You then need to decide how to call p:store. You could use XPath if, provided your XProc parser supports XPath 2.0 (like XMLCalabash does). But I’d recommend using a p:choose like this:
<p:choose>
<p:when test="ends-with($path, '.xhtml')">
<p:store
doctype-public="-//W3C//DTD XHTML 1.0 Frameset//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"
encoding="UTF-8"
media-type="text/html"
method="xhtml"
omit-xml-declaration="no">
<p:with-option name="href" select="$path"/>
</p:store>
</p:when>
<p:otherwise>
<p:store
encoding="UTF-8"
media-type="application/xml"
method="xml"
omit-xml-declaration="no">
<p:with-option name="href" select="$path"/>
</p:store>
</p:otherwise>
</p:choose>
(This entire p:choose replaces the p:store you already have.)
The test in p:when only looks at $path, but you could include a test for $root as well, if you like.
It also requires you to use .xhtml as extension in your xsl:result-document statements for the HTML output, but you can easily tweak that if you like.
The var and the choose should be enough to get your XML written properly, at least.
Good luck!

Related

Why is read_xml not properly reading an xml file in R?

I am reading the url below with this code in R. But, for some reason, R is not reading or recognizing the "language_dependence" poll that clearly exists in the file if you just copy and paste the below url into a browser.
library(XML)
library(xml2)
url <- https://boardgamegeek.com//xmlapi//boardgame//44669&type=boardgame,boardgameexpansion,boardgameaccesory,rpgitem,rpgissue,videogame&versions=1&stats=1&videos=1&marketplace=1&comments=1&pricehistory=1
data <- read_xml(url)
xmlfile <- xmlParse(data)
xmltop = xmlRoot(xmlfile)
This is the language_dependence poll as it looks like in xmltop, from my code above.
xmltop
<poll name="language_dependence" title="Language Dependence" totalvotes="0">
</poll>
It should look like this:
<poll name="language_dependence" title="Language Dependence" totalvotes="0">
<results>
<result level="1" value="No necessary in-game text" numvotes="0"/>
<result level="2" value="Some necessary text - easily memorized or small crib sheet" numvotes="0"/>
<result level="3" value="Moderate in-game text - needs crib sheet or paste ups" numvotes="0"/>
<result level="4" value="Extensive use of text - massive conversion needed to be playable" numvotes="0"/>
<result level="5" value="Unplayable in another language" numvotes="0"/>
</results>
</poll>
I am out of ideas as what could be going on here. This only happens once in a while, as there are thousandso of simiilar URL's I am reading just fine with this code. Am I reading it in wrong or something? Is there a better way to read it in or parse it? I don't see anything wrong with the xml, but maybe I'm just missing something obvious. Thank you!!

QR code missing characters after printing with Zebra S4M

I am programming a Zebra S4M template:
^FX[Fonts]^FS
^FX[Graphics]^FS
^FX[Format]^FS
CT~~CD,~CC^~CT~
^XA
^DFR:QR.ZPL^FS
~TA000~JSN^LT0^MNW^MTT^PON^PMN^LH0,0^JMA^PR3,3^MD10^LRN^CI0
^MMT
^PW980
^LL0461
^LS0
^FT137,424^BQN,2,7
^FN24^FDQR_CUST_CODE^FS
^XZ
The line in question is ^FN24^FDQR_CUST_CODE^FS, where the variable is supplied in a .xml file
<?xml version="1.0" standalone="no"?>
<!DOCTYPE labels SYSTEM "label.dtd">
<labels _FORMAT="R:QR.ZPL" _QUANTITY="1" _PRINTERNAME="Printer 1" _JOBNAME="LBL101">
<label>
<variable name="QR_CUST_CODE">11112345678</variable>
</label>
</labels>
The resulting code only contains values 12345678, so I am missing first 3x1.
Any suggestions? Tried to add QA to the FD but it does not work.
When creating a QR Code in ZPL, the ^FD command has additional arguments that must be set before the data is added.
Change your last line as show here:
From:
^FN24^FDQR_CUST_CODE^FS
To:
^FN24^FDMM,NQR_CUST_CODE^FS
Below is example from the BQ Command guide that should help you further.
https://support.zebra.com/cpws/docs/zpl/BQ_Command.pdf

What language is this file generated by Mascot version 1.0 written in?

I have been assigned a task to retrieve information from files that were processed from raw mass spectrophotometry data (file.mzML).
These files have just ".data" as extension and when I open them, I cannot recognize the language and therefore I cannot load them into R and work on them.
The files with the .data extension are contained in this folder:
ftp://ftp.pride.ebi.ac.uk/pride/data/archive/2015/11/PXD000299/
Could someone take a look at any of the files.data and tell me the language is in (e.g. F010439)?
EDIT: these is are some snippets
Lines 1 to 10
MIME-Version: 1.0 (Generated by Mascot version 1.0)
Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08jU534c0p
--gc0p4Jq0M2Yt08jU534c0p
Content-Type: application/x-Mascot; name="parameters"
LICENSE=Licensed to: INRA Tours, P-F Proteomique Analytique & Fonction.,Nouzilly (0085-0000003524/1), (2 processors).
MP=
NM=
COM=
Lines 120 to 130
NeutralLoss3_master=63.998285
--gc0p4Jq0M2Yt08jU534c0p
Content-Type: application/x-Mascot; name="unimod"
<?xml version="1.0" encoding="UTF-8" ?>
<umod:unimod xmlns:umod="http://www.unimod.org/xmlns/schema/unimod_2" majorVersion="2" minorVersion="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.unimod.org/xmlns/schema/unimod_2 unimod_2.xsd">
<umod:elements>
<umod:elem avge_mass="1.00794" full_name="Hydrogen" mono_mass="1.007825035" title="H"/>
<umod:elem avge_mass="2.014101779" full_name="Deuterium" mono_mass="2.014101779" title="2H"/>
<umod:elem avge_mass="6.941" full_name="Lithium" mono_mass="7.016003" title="Li"/>
<umod:elem avge_mass="12.0107" full_name="Carbon" mono_mass="12" title="C"/>
It looks like that file is MIME-encoded "multi-part" file that contains (at least) two components files.
You can decode the multi-part using a MIME decoder.
The first component file looks like a simple "name=value" property file
The second component file is XML.
I don't know if this is relevant, but a search for Mascot file format gave me this reference page:
http://www.matrixscience.com/help/data_file_help.html
Also, there were some interesting hits when I searched for parser "x-mascot" and parser mascot. If you can find an existing parser, then you may be able to save yourself implementation effort.

Source port with default fallback value?

I have an XProc step where I would like the input source to work like this:
if a URL is provided on the command line using -isource=foo.xml, then the document at that URL is used as the source document;
if no URL is provided, then the document default.xml should be used.
Is it possible to obtain this behaviour in XProc?
As suggested by Florent on the XProc mailing list, using a p:document inside the p:input works just fine as a default. Specifying something else from outside simply overrides it:
<p:declare-step version="1.0" xmlns:p="http://www.w3.org/ns/xproc"
name="main">
<p:input port="source">
<p:document href="default.xml"/>
</p:input>
<p:output port="result"/>
<p:identity/>
</p:declare-step>
Run it with:
calabash test.xpl
and:
calabash --input source=myinput.xml test.xpl
to see the difference..
HTH!

How to compile a SWC file with mulitple namespaces

I'm trying to compile an SWC file from a list of given ActionScript classes. I'm using the compc compiler. The problem is that there are so many classes grouped into multiple namespaces that I am finding it very tedious to specify each individual class to be included in the SWC. Is there any easier way of doing this like just simply specifying a root directory of these classes?
At the moment I have something like this:
<?xml version="1.0"?>
<flex-config xmlns="http://www.adobe.com/2006/flex-config">
<output>C:\SomeFolder\testSWC.swc</output>
<compiler>
<source-path>.</source-path>
</compiler>
<include-classes>
<class>SomeNamespaceOne.One</class>
<class>SomeNamespaceOne.Two</class>
<class>SomeNamespaceOne.Three</class>
<class>SomeNamespaceOne.Four</class>
...
<class>SomeNamespaceFifty.One</class>
</include-classes>
</flex-config>
But I want something like this:
<?xml version="1.0"?>
<flex-config xmlns="http://www.adobe.com/2006/flex-config">
<output>C:\SomeFolder\testSWC.swc</output>
<compiler>
<source-path>. </source-path>
</compiler>
<include-classes>
<class>SomeRootDirectoryOfClassesToCompile</class>
</include-classes>
</flex-config>
Is this possible?
We wanted something similar, in "Ant".
I am assuming you are not using Flex Builder. In that case, I will definitely recommend using Ant and Flex Ant tasks available from Adobe. Even when you use Ant, its not easy doing what you want to do, so I am including our code below.
Following is our code. I don't remember where I got the idea from, so cannot thank the source for it :)
<pathconvert property="XXX.classes" pathsep=" ">
<fileset dir="${basedir}/XXX/src">
<include name="**/*.as"/>
<include name="**/*.mxml"/>
</fileset>
<compositemapper>
<packagemapper from="${basedir}\XXX\src\*.as" to="*"/>
<packagemapper from="${basedir}/XXX/src/*.as" to="*"/>
<packagemapper from="${basedir}\XXX\src\*.mxml" to="*"/>
<packagemapper from="${basedir}/XXX/src/*.mxml" to="*"/>
</compositemapper>
</pathconvert>
<compc optimize="true" debug="false"
include-classes="${XXX.classes}" output="${BUILD_FOLDER}/XXX.swc">
</compc>
Like Tanmay said, you should use the ANT tasks to make life easier, but there's an even simpler wach include an entire directory in the compc ant task. If you just need to include everything in src.dir you can do it like this:
<compc output="${target.dir}/foo.swc">
<source-path path-element="${src.dir}"/>
<include-sources dir="${src.dir}">
<include name="**/*" />
</include-sources>
</compc>

Resources